Почему цикл For в java дает разные результаты, если мы поместим пробел в инструкцию print, а затем выведем переменную

0

Вопрос

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);
    }
}

Пожалуйста, обратите внимание, что если я удалю пробел в инструкции по печати, это даст другие результаты? любая подсказка поможет и будет оценена по достоинству

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

Лучший ответ

-1

Этот - забавный. Вы видите, когда вы ставите пробел, результат такой, какой вы хотите

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

Но когда вы удаляете пробел, ответ все равно приходит правильно, но он соединяется с цифрой 2 в утверждении, т. е.

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

На других языках

Эта страница на других языках

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