0
can someone simplify java code - for (int x=6; x<x*x;--x) { System.out.println(x):
can someone simplify it - for (int x=6; x<x*x;--x) { System.out.println(x):
5 Answers
+ 6
x < x*x is true to all the integers except {-1,0,1}, if you start on 6 you will always stop on 1, so the code will print {6 5 4 3 2}. One way you can do that and it's to do:
for (int x= 6; x > 1; x--) System.out.println(x);
Note: Assintotically speaking both are the same, if you are trying to find all the integers below 7 that are less then their squares, your version is better since it's easier to understand. Now, if you want to print only 6 until 2 your version is hard to understand so to keep ir simple you use the one I proposed.
Idk if I could answer your question, but good coding for you!
+ 1
Where did you get the code, Challenges?
x<x*x is tricky as TomĂĄs explained you can also print that to see :)
0
Yeah i got this code from challenge itself
0
TomĂĄs there should be x--
0
zemiak Yes, you're right, thanks. I already fixed it.