Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- public class Q5 {
- public static void main(String args[]){
- int i = 10;
- int j = 12;
- i+=++j;
- System.out.println(i);
- }
- }
b. Program will print 23
c. Program will print 22
d. Program will print 12
Answer:
b is the correct choice. j is incremented before the assignment. Remember that ++j is pre-increment. So, value of j is incremented first and then assigned. j++ would have been assigned first and then incremented. Don't forget that it's i+= so 13 would be added to 10 (value of i) to make 23.

asdasd
Post new comment