Java - Print all integers between 1 and 10 using a while-loop

Description

Print all integers between 1 and 10 using a while-loop

Demo

public class Main {
  public static void main(String[] args) {
    int i = 1;// www .  java 2s  . co m
    while (i <= 10) {
      System.out.println(i);
      i++;
    }

  }
}

Result

The above code can also be rewritten as

Demo

public class Main {
  public static void main(String[] args) {
    int i = 0;//from w  w w.  j a v a 2  s  .c  o  m
    while (++i <= 10) {
      System.out.println(i);
    }

  }
}

Result

Related Example