Floyd’s triangle star pattern in java

Let’s learn Floyd’s triangle star pattern in java.

Floyd’s triangle star pattern in java

Let’s learn java program to print floyd’s triangle with stars in java. Here’s the java program.

import java.util.Scanner;
public class FloydTriangleStars
{
   public static void main(String[] args) 
   {
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the number of rows of floyd's triangle you want to print: ");
      int rows = sc.nextInt();
      System.out.println("Printing floyd's triangle with stars in java");
      for(int a = 1; a <= rows; a++)
      {
         for(int b = 1; b <= a; b++)
         {
            System.out.print("* ");
         }
         System.out.println();
      }
      sc.close();
   }
}


Output:

Enter the number of rows of floyd's triangle you want to print: 4
Printing floyd's triangle with stars in java
*  
*  *
*  *  *
*  *  *  *

Enter the number of rows of floyd's triangle you want to print: 6
Printing floyd's triangle with stars in java
*  
*  *
*  *  *
*  *  *  *
*  *  *  *  *
*  *  *  *  *  *

Also read – Strings in java