Question discussion

Determine output:public class Test{ static int i = 5; public static void main(String... args){ System.out.println(i++); System.out.println(…

303265Medium 1 reply 2,305 views
35
Determine output:public class Test{ static int i = 5; public static void main(String... args){ System.out.println(i++); System.out.println(i); System.out.println(++i); System.out.println(++i+i++); }}
  • A6 6 6 16
  • B6 7 6 16
  • C5 6 7 16
  • D5 6 6 16
  • ENone of these
Correct answer: C

Discussion 1

0
CCommunity
5 6 7 16

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).