Java Loop Error -
hi i'm running simple loop supposed output numbers 0-10, when program run, nothing appears in output box, yet program doesn't throw errors. here loop:
for(int num = 0; num <= 10; num++){ system.out.println("num = " + num); }
since op clarified in comment intention print numbers 1-9:
you start loop num = 0. means start printing 0. if supposed print 1 first number, loop should start for(int num = 1;.
also, @gersee wrote in comment, condition of loop should num < 10 if intention print 9 last number. condition of loop says num <= 10, still valid when num == 10, , therefore results in code printing 10.
Comments
Post a Comment