Given the code fragment:
int a = 0;
a++;
System.out.println(a++);
System.out.println(a);
What is the result?
A.
1
2
B.
2
2
C.
12
D.
1
1
Explanation:
The first println prints variable a with value 1 and then increases the variable to 2.
Given the code fragment:
int a = 0;
a++;
System.out.println(a++);
System.out.println(a);
What is the result?
Given the code fragment:
int a = 0;
a++;
System.out.println(a++);
System.out.println(a);
What is the result?
A.
1
2
B.
2
2
C.
12
D.
1
1
Explanation:
The first println prints variable a with value 1 and then increases the variable to 2.
A
The Answer is A.
The postfix operation (a++) is executed immediately after the variable a is used in a statement. The prefix operation (a++) is executed immediate before the variable a is used in a statement.