You are here: Home / Topics / Nested while Loop example in Java

Nested while Loop example in Java

Filed under: Java on 2023-08-18 06:54:55

// Nested while loop example

public class NestedWhile{

   public static void main(String[] args) {
       int a = 1, b;

       while (a <= 5) {
           b = 1;
           while (b <= a) {
               System.out.print("* ");
               b++;
           }
           a++;
           System.out.println();
       }
   }
}

 

Output:

*
* *
* * *
* * * *
* * * * *

 

About Author:
Y
Yatendra Sir     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.