Let’s learn floyd’s triangle star pattern in java.
Floyd’s triangle star pattern in java
Here we are using nested for loop to print floyd’s triangle star pattern. Let’s learn java program to print floyd’s triangle with stars in java.
import java.util.Scanner; public class FloydTriangleStars { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Please enter the number of rows of floyd's triangle you want to print: "); int rows = sc.nextInt(); System.out.println("Printing floyd's triangle star pattern in java"); for(int a = 0; a <= rows; a++) { for(int b = 0; b <= a; b++) { System.out.print("*"); } System.out.println(); } sc.close(); } }
Output:
Please enter the number of rows of floyd’s triangle you want to print: 10
Printing floyd’s triangle star pattern in java
* ** *** **** ***** ****** ******* ******** ********* **********
Here’s java program to display mirrored right triangle star pattern.
import java.util.Scanner; public class FloydTriangleStars { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Please enter the number of rows: "); int rows = sc.nextInt(); for(int a = 1; a <= rows; a++) { for(int b = 1; b <= rows - a; b++) { System.out.print(" "); } for(int c = 1; c <= a; c++) { System.out.print("*"); } System.out.println(); } sc.close(); } }
Output:

Now let’s see java program to display reverse right triangle star pattern.
import java.util.Scanner; public class FloydTriangleStars { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Please enter the number of rows: "); int row = sc.nextInt(); for(int a = row; a >= 1; a--) { for(int b = 1; b <= a; b++) { System.out.print("*"); } System.out.println(); } sc.close(); } }
Output:

Also read – Strings in java