+ 3
Java question . Why the answer is coming 80 instead of coming 200. Please explain me
class xyz{ public static void main (){ int p =200; while (true) { if(p<100) break; p=p-20; } System.out.print(p); } }
6 Respostas
+ 4
Dry run
p=200
200<100 //false
200-20=180
180<100// false
.
160<100//false
.
140<100//false
.
120<100//false
.
100<100//false
100-20=80
80<100// true and P=80
Break statement run and while loop terminat
+ 6
The condition inside while loop get break when p<100 ,otherwise ithe statement p=p-20 will run, in simple words program will subtract 20 from variable p and stop when less than 100.
+ 2
Abhishek Topno Of course I could it explain, but if you could it test yourself you could learn much more as I already said.
Debugging is the routine process of locating and removing bugs, errors or abnormalities from programs. It's a must have skill for any developer. With such as tool you can also see how your code works as well as states of your variables.
If you do not have a environment with a debugger, you could test it here on the SL Playground with a few additional print statements. I.e. you can set one print statement for p variable within the while loop at its end. So you could see what happends with the p etc.
+ 2
Thx
+ 1
You can test it yourself then can you see how that works. Try to do it. So can you much learn.
+ 1
Can you explain me