What will be displayed, if the following code is compiled and executed:

public class Main {
    public static void main(String args[]) {
        System.out.println("2 + 2 = " + 2 + 2);
    }
}
Explanation
Actions are executed in order from left to right. Due to the fact that the string is the first operand, the concatenation is performed.
In order to get a mathematically correct example, you can modify the order of operations execution with the help of parentheses:
System.out.println("2 + 2 = " + (2 + 2));

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты