Can I get comprehensive explanation on this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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) _____

14th Mar 2019, 10:25 AM
Olalekan Ademola
Olalekan Ademola - avatar
3 Answers
+ 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
14th Mar 2019, 10:47 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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
14th Mar 2019, 10:48 AM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
0
Thank you, I got it better
14th Mar 2019, 1:44 PM
Olalekan Ademola
Olalekan Ademola - avatar