Dlaczego pętla For w języku java daje różne wyniki, jeśli umieścimy spacji w instrukcji print, a następnie ustawcie zmienną

0

Pytanie

public class Countingtable {
    public static void main(String[] args) {
        // write a program to count/increase a number by 2 everytime.
        int number1;
        for (number1 = 2; number1 <= 20; number1++)
            System.out.println("this number is a multiple of 2  " + number1);
    }
}

Proszę zwrócić uwagę, że jeśli usunę spacji w instrukcji drukowania, to daje inne wyniki? każda wskazówka pomoże i będzie w pełni docenione

System.out.println("this number is a multiple of 2" + number1);
java
2021-11-24 06:52:27
1

Najlepsza odpowiedź

-1

Ten zabawny. Widzisz, kiedy stawiasz spację, wynik taki, jaki chcesz

This number is multiple of 2 2
This number is multiple of 2 3
This number is multiple of 2 4

Ale po usunięciu spacji, odpowiedź i tak przychodzi poprawnie, ale łączy się z cyfrą 2 w twierdzeniu, tj.

This number is multiple of 22 -- here 2 is from the statement and the next one is from answer
This number is multiple of 23 -- here 2 is from the statement and the next one is from answer
This number is multiple of 23 -- here 2 is from the statement and the next one is from answer
2021-11-24 07:02:48

W innych językach

Ta strona jest w innych językach

Русский
..................................................................................................................
Italiano
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................