While Loop Example, print 1 to 8 different way

Java Programming Language / Decision Making and Looping in java

1308

Program:

 public class While_loop {

    public static void main(String args[]) {
        /* local variable Initialization */
        int n = 1, times = 8;

        /* while loops execution */
        while (n <= times) {
            System.out.println("Java while loops:" + n);
            n++;
        }
    }
}

Output:

Java while loops:1
Java while loops:2
Java while loops:3
Java while loops:4
Java while loops:5
Java while loops:6
Java while loops:7
Java while loops:8
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.