While Loops

This loop prints from 10 down to 0. In the second program we combine the decrement num with -- as part of the print statement.

1
2
3
4
5
6
7
8
9
10
11
12
13
// Print 10 9 8 7 6 5 4 3 2 1 0 Blast Off!
package numbers;
//import java.util.*;
public class Numbers {
  public static void main(String[] args) {
    int num=10;
    while (num>=0) {
      System.out.print(num+" ");
      num--;
    }
    System.out.println(); 
  }//main
}//class
CODE
1
2
3
4
5
6
7
8
9
10
// Print 10 9 8 7 6 5 4 3 2 1 0 Blast Off!
package numbers;
public class Numbers {
  public static void main(String[] args) {
    int num=10;
    while (num>=0) 
      System.out.print(num-- +" ");
    System.out.println(); 
  }//main
}//class
CODE

NEXT: