Print all integers between 1 and 10 using a while-loop
public class Main { public static void main(String[] args) { int i = 1;//www . ja v a 2 s .c om while (i <= 10) { System.out.println(i); i++; } } }
The above code can also be rewritten as
public class Main { public static void main(String[] args) { int i = 0;/*from w ww . ja va 2 s.c o m*/ while (++i <= 10) { System.out.println(i); } } }