Write a Java Program to print reverse mirrored right triangle star pattern using for loop. This Java reverse mirrored right angled triangle example prints star or empty space based on the If condition.
package ShapePrograms; import java.util.Scanner; public class RevMirroredRightTri1 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Reverse Mirrored Right Triangle Rows = "); int rows = sc.nextInt(); System.out.println("Reverse Mirrored Right Triangle Star Pattern"); for (int i = 1 ; i <= rows; i++ ) { for (int j = 1 ; j <= rows; j++ ) { if(j < i) { System.out.print(" "); } else { System.out.print("*"); } } System.out.println(); } } }
In this Java reverse mirrored right triangle star pattern program, we replaced for loops with while loops.
package ShapePrograms; import java.util.Scanner; public class RevMirroredRightTri2 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Reverse Mirrored Right Triangle Rows = "); int rows = sc.nextInt(); int i = 1, j; while( i <= rows ) { j = 1 ; while(j <= rows) { if(j < i) { System.out.print(" "); } else { System.out.print("*"); } j++; } System.out.println(); i++; } } }
Enter Reverse Mirrored Right Triangle Rows = 10
**********
*********
********
*******
******
*****
****
***
**
*
Java Program to Print Reverse Mirrored Right Triangle Star Pattern using do while loop
package ShapePrograms; import java.util.Scanner; public class RevMirroredRightTri3 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Reverse Mirrored Right Triangle Rows = "); int rows = sc.nextInt(); int i = 1, j; do { j = 1 ; do { if(j < i) { System.out.print(" "); } else { System.out.print("*"); } } while(++j <= rows); System.out.println(); } while( ++i <= rows ); } }
Enter Reverse Mirrored Right Triangle Rows = 14
**************
*************
************
***********
**********
*********
********
*******
******
*****
****
***
**
*
In this Java example, the RevMirroredRightTriangle function prints a given symbol’s reverse mirrored right triangle pattern.
package ShapePrograms; import java.util.Scanner; public class RevMirroredRightTri4 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Reverse Mirrored Right Triangle Rows = "); int rows = sc.nextInt(); System.out.print("Character for Reverse Mirrored Right Triangle Pattern = "); char ch = sc.next().charAt(0); RevMirroredRightTriangle(rows, ch); } public static void RevMirroredRightTriangle(int rows, char ch) { for (int i = 1 ; i <= rows; i++ ) { for (int j = 1 ; j <= rows; j++ ) { if(j < i) { System.out.print(" "); } else { System.out.print(ch); } } System.out.println(); } } }
Enter Reverse Mirrored Right Triangle Rows = 17
Character for Reverse Mirrored Right Triangle Pattern = #
#################
################
###############
##############
#############
############
###########
##########
#########
########
#######
######
#####
####
###
##
#