+ 2

Java

What is the output of this code? int result = 0; for (int i = 0; i < 5; i++) { if (i == 3) { result += 10; } else { result += i; } } System.out.println(result);

18th Nov 2018, 1:17 PM
Utkarsh Sharma
Utkarsh Sharma - avatar
3 Respuestas
+ 16
Utkarsh Sharma I guess this question is to ask how the output is 17 . here , loop runs for 0,1,2,3,4 // ie result = result+ 0+1+2+10+4 = 17 //just add 10 in place of 3 bcz of condition
18th Nov 2018, 3:31 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 7
SL has a Code Playground, you should write the code and try to practice! You should check out what the output is! Please, read our guidelines: https://www.sololearn.com/discuss/1316935/?ref=app
18th Nov 2018, 1:38 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 4
17
18th Nov 2018, 1:26 PM
Al Toe