+ 1

[SOLVED] plz tell me the output of the following

public class Program { public static void main(String[] args) { int num1 = 4; int num2 =8; num2 += ++ num1; System.out.println(num2); } }

25th Nov 2017, 8:15 AM
Lucky
Lucky - avatar
6 Answers
+ 11
++num1 increments num1 and returns the result (4 + 1 = 5). num2 += ++num1 => num2 += 5 num2 += 5 => num2 = num2 + 5 = 8 + 5 = 13 Hence, 13 is printed.
25th Nov 2017, 9:00 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 7
13
10th Dec 2017, 10:18 AM
Vyshnav Vishnu
Vyshnav Vishnu - avatar
+ 3
13
25th Nov 2017, 8:22 AM
Peerzada Burhan
Peerzada Burhan - avatar
+ 1
plz tello
25th Nov 2017, 8:19 AM
Lucky
Lucky - avatar
+ 1
thanks
25th Nov 2017, 8:23 AM
Lucky
Lucky - avatar
0
thanks
25th Nov 2017, 9:02 AM
Lucky
Lucky - avatar