Welcome Guest | Sign in | Register
Variables and Loops - Discussion Page For Q.2982 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Variables and Loops > Questions and Answers

Q: What is the output for the below code ?

1. public class Test {
2. static int i =5;
3. public static void main(String... args) {
4. System.out.println(i++);
5. System.out.println(i);
6. System.out.println(++i);
7. System.out.println(++i+i++);
8.
9. }
10. }
A. 5 6 7 16 B. 6 6 6 16
C. 6 6 7 16 D. 5 6 6 16

Answer and Explanation

Answer:5 6 7 16

Explanation:
i++ : print value then increment (postfix - increment happens after the value of the
variable is used) ++i : increment the print (prefix - increment happens before the value of the variable is used)

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.