What will the following code print out?

public class Test {
    public static void main(String[] args) {
        int f;
        f = 5;
        f = ++f + f++;
        System.out.println(f);
    }
}
Explanation
1. f becomes equal to 5
2. ++f is equal to 6 (f becomes equal to 6)
3. f++ is equal to 6 (f becomes equal to 7)
4. The sum of 6 + 6 = 12 is written into f

Следи за CodeGalaxy

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

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