0

Compiler says tume limit exceeded in output .

So I just started learning Java and got to the section of while loops and for some reason the compiler is returning time limit exceeded when I try to run this code :plz help public class Myclass{ public static void main(String[] args){ int x=7; while (x>0);{ System.out.println(x); x++; } } }

29th Mar 2018, 4:24 PM
Amitesh Shrey
Amitesh Shrey - avatar
4 Antworten
+ 1
thanks that helps !!
30th Mar 2018, 12:59 AM
Amitesh Shrey
Amitesh Shrey - avatar
+ 4
It is an infinite loop, because x is always larger than 0. Try doing x-- instead of x++.
29th Mar 2018, 4:27 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
your ; after while (x< 10); is the loop remove it to run.
29th Mar 2018, 8:23 PM
John Wells
John Wells - avatar
0
I tried it and changed the code to still turning up the same msg public class Myclass{ public static void main(String[] args){ int x=7; while (x< 10);{ System.out.println(x); x++; } } }
29th Mar 2018, 5:27 PM
Amitesh Shrey
Amitesh Shrey - avatar