0

CODE BREAKDOWN

can someone breakdown this code please. I dont understand how result = 17. int result = 0; for (int i = 0; i < 5; i++) { if (i == 3) { result += 10; } else { result += i; } } System.out.println(result);

27th Feb 2019, 10:07 AM
James Marianne
James Marianne - avatar
4 Réponses
+ 13
● code run for i=0, 1, 2, 3, 4 . //adding each value of i to result & when i==3 add 10 instead of 3, answer by Jay Matthews sir make it clear
27th Feb 2019, 4:49 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 10
i=0; In first itration if (i==3) false else => result+=i; result = 0; i=1; In second itration if (i==3) false else => result+=i; result = 1; i=2; In third itration if (i==3) false else => result+=i; result = 3; i=3; In forth itration if (i==3) result += 10; result = 13; i=4; In fifth itration if (i==3) false else => result+=i; result = 17;
27th Feb 2019, 5:37 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
0
Thank you guys
4th Mar 2019, 9:17 AM
James Marianne
James Marianne - avatar
0
d
21st Jul 2019, 6:28 PM
James Marianne
James Marianne - avatar