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
Зареєструйся Зараз
або Підпишись на майбутні тести