What will be the result of the following code execution?

public class Main {
    public static void main(String[] args) {
        int i = 0;
        int j = 1;
        System.out.println(i += (j < i) ? (2) : (3)); //1
    }
}
Explanation
Conditional statement (condition) ? (value1) : (value2) is used in the provided example. Condition is placed before the question mark, and is followed by two returned results separated by : sign. If condition results in true then the first value will be returned, othervise - second value will be returned.

Следи за CodeGalaxy

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

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