Page 205 - ComputerScience_Class_11
P. 205

The output of the preceding program is as follows:

                       BlueJ: Terminal Window - Java
                   Options

                  2
                  44
                  666


                 •  Nested while loop: The while loop inside another while loop is called a nested while loop.
                   For example:

                                 Write a Java program using nested while loops to print the following pattern:
                  Program 8
                                 2
                                 3 4
                                 4 5 6
                   1      import java.util.Scanner;
                   2      public class NestedWhileLoop {

                   3          public static void main(String[] args) {
                   4              int i;
                   5              int j;
                   6              i=1;

                   7              while(i<=3)
                   8              {
                   9                  j=1;
                  10                  while(j<=i)
                  11                  {

                  12                      System.out.print((i+j)+ " ");
                  13                      j++;
                  14                  }
                  15                  System.out.println();
                  16                  i++;

                  17              }
                  18          }
                  19      }

                 The output of the preceding program is as follows:

                       BlueJ: Terminal Window - Java

                   Options

                  2
                  3 4
                  4 5 6




                                                                                              Statements and Scope  203
   200   201   202   203   204   205   206   207   208   209   210