Write a Java program to print mirrored right triangle alphabets pattern using for loop.
package Alphabets; import java.util.Scanner; public class MirroredRightTriAlp1 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Mirrored Right Triangle of Alphabets Rows = "); int rows = sc.nextInt(); System.out.println("The Mirrored Right Triangle Alphabets Pattern"); int alphabet = 65; for (int i = 0; i <= rows; i++) { for (int j = 1; j <= rows - i; j++ ) { System.out.print(" "); } for(int k = 0; k <= i; k++) { System.out.print((char)(alphabet + i)); } System.out.println(); } } }
This Java program prints the mirrored right angled triangle pattern of alphabets using while loop.
package Alphabets; import java.util.Scanner; public class MirroredRightTriAlp2 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Mirrored Right Triangle of Alphabets Rows = "); int rows = sc.nextInt(); System.out.println("The Mirrored Right Triangle Alphabets Pattern"); int alphabet = 65; int j, k, i = 0; while(i <= rows) { j = 1; while(j <= rows - i ) { System.out.print(" "); j++; } k = 0; while( k <= i) { System.out.print((char)(alphabet + i)); k++; } System.out.println(); i++; } } }
Enter Mirrored Right Triangle of Alphabets Rows = 18
The Mirrored Right Triangle Alphabets Pattern
A
BB
CCC
DDDD
EEEEE
FFFFFF
GGGGGGG
HHHHHHHH
IIIIIIIII
JJJJJJJJJJ
KKKKKKKKKKK
LLLLLLLLLLLL
MMMMMMMMMMMMM
NNNNNNNNNNNNNN
OOOOOOOOOOOOOOO
PPPPPPPPPPPPPPPP
QQQQQQQQQQQQQQQQQ
RRRRRRRRRRRRRRRRRR
SSSSSSSSSSSSSSSSSSS
This Java example uses the do while loop to display the right angled triangle of alphabets pattern.
package Alphabets; import java.util.Scanner; public class MirroredRightTriAlp3 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Mirrored Right Triangle of Alphabets Rows = "); int rows = sc.nextInt(); System.out.println("The Mirrored Right Triangle Alphabets Pattern"); int alphabet = 65; int j, k, i = 0; do { j = 1; do { System.out.print(" "); } while(j++ <= rows - i ); k = 0; do { System.out.print((char)(alphabet + i)); } while( ++k <= i); System.out.println(); } while(++i < rows); } }
Enter Mirrored Right Triangle of Alphabets Rows = 15
The Mirrored Right Triangle Alphabets Pattern
A
BB
CCC
DDDD
EEEEE
FFFFFF
GGGGGGG
HHHHHHHH
IIIIIIIII
JJJJJJJJJJ
KKKKKKKKKKK
LLLLLLLLLLLL
MMMMMMMMMMMMM
NNNNNNNNNNNNNN
OOOOOOOOOOOOOOO