Write a Java Program to print inverted mirrored right triangle star pattern using for loop.
package ShapePrograms; import java.util.Scanner; public class InvertedMirroredRightTriangle1 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Inverted Mirrored Right Triangle Pattern Rows = "); int rows = sc.nextInt(); System.out.println("Printing Inverted Mirrored Right Triangle Star Pattern"); for (int i = rows; i > 0; i-- ) { for (int j = rows - i ; j > 0; j-- ) { System.out.print(" "); } for (int k = 0 ; k < i; k++ ) { System.out.print("*"); } System.out.println(); } } }
In this Java inverted mirrored right angled triangle star pattern program, we replaced for loops with while loops.
package ShapePrograms; import java.util.Scanner; public class InvertedMirroredRightTriangle2 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Inverted Mirrored Right Triangle Pattern Rows = "); int rows = sc.nextInt(); System.out.println("-- Printing Inverted Mirrored Right Triangle Star Pattern --"); int i = rows; while(i > 0) { int j = rows - i ; while( j > 0) { System.out.print(" "); j--; } int k = 0 ; while ( k < i ) { System.out.print("*"); k++; } System.out.println(); i--; } } }
Enter Inverted Mirrored Right Triangle Pattern Rows = 11
-- Printing Inverted Mirrored Right Triangle Star Pattern --
***********
**********
*********
********
*******
******
*****
****
***
**
*
Java Program to Print Inverted Mirrored Right Triangle Star Pattern using do while loop
package ShapePrograms; import java.util.Scanner; public class InvertedMirroredRightTriangle3 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Inverted Mirrored Right Triangle Pattern Rows = "); int rows = sc.nextInt(); System.out.println("-- Printing Inverted Mirrored Right Triangle Star Pattern --"); int j, k, i = rows; do { j = rows - i ; do { System.out.print(" "); }while( j-- > 0); k = 0 ; do { System.out.print("*"); }while (++k < i ); System.out.println(); }while(--i > 0); } }
Enter Inverted Mirrored Right Triangle Pattern Rows = 14
-- Printing Inverted Mirrored Right Triangle Star Pattern --
**************
*************
************
***********
**********
*********
********
*******
******
*****
****
***
**
*
In this example, the InvertedMirroredRightTrianglePat function prints a given symbol’s inverted mirrored right triangle pattern.
package ShapePrograms; import java.util.Scanner; public class InvertedMirroredRightTriangle4 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Inverted Mirrored Right Triangle Pattern Rows = "); int rows = sc.nextInt(); System.out.print("Enter Character for Inverted Mirrored Right Triangle = "); char ch = sc.next().charAt(0); InvertedMirroredRightTrianglePat(rows, ch); } public static void InvertedMirroredRightTrianglePat(int rows, char ch) { for (int i = rows; i > 0; i-- ) { for (int j = rows - i ; j > 0; j-- ) { System.out.print(" "); } for (int k = 0 ; k < i; k++ ) { System.out.print(ch); } System.out.println(); } } }
Enter Inverted Mirrored Right Triangle Pattern Rows = 17
Enter Character for Inverted Mirrored Right Triangle = @
@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@
@@@@@@@@@@@@@
@@@@@@@@@@@@
@@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@
@@@@@@@@
@@@@@@@
@@@@@@
@@@@@
@@@@
@@@
@@
@