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

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes