0
Can I get comprehensive explanation on this code?
What is the outcome of this code? Int smart = 0 For (x =0; x < 5; x++) { If (x==3) { Smart + =10; } else {smart + =x; } } System.out.printIn(smart) _____
3 odpowiedzi
+ 3
for (x = 0; x < 5; x++)
we know that the loop runs for values x = 0 until x = 4.
if (x == 3)
smart += 10;
else
smart += x;
So when x is 3, we add 10 to smart. When x is not 3, we add x to smart.
0 + 1 + 2 + 10 + 4
= 17
+ 2
Try to run the code in playground and when you don't understand add
print codes to check the values of variables.
You can do it for example as below :
https://code.sololearn.com/c3C684UIjFbl/#java
0
Thank you, I got it better