You are here: Home / Topics / Print star Patter 2 logic in Java

Print star Patter 2 logic in Java

Filed under: Java on 2023-08-18 06:42:09

// for loop and while loop

public class ForWhile {

   public static void main(String[] args) {

       for (int i = 1; i <= 5; i++) {
           int j = i;

           while (j <= 5) {
               System.out.print(j);
               j++;
           }

           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.