Write a Java program to print right triangle of incremental alphabets pattern using for loop.
package Alphabets; import java.util.Scanner; public class RightTriIncAlp1 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Right Triangle of Incremented Characters Rows = "); int rows = sc.nextInt(); System.out.println("Right Triangle of Incremented Row Characters Pattern"); int alphabet = 65; for (int i = 0; i <= rows - 1; i++) { for (int j = i; j >= 0; j-- ) { System.out.print((char)(alphabet + j) + " "); } System.out.println(); } } }
This Java example prints the right angled triangle pattern of incremental alphabets or ascending order using while loop.
package Alphabets; import java.util.Scanner; public class RightTriIncAlp2 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Right Triangle of Incremented Characters Rows = "); int rows = sc.nextInt(); System.out.println("Right Triangle of Incremented Row Characters Pattern"); int i, j, alphabet = 65; i = 0; while(i <= rows - 1) { j = i; while(j >= 0 ) { System.out.print((char)(alphabet + j) + " "); j--; } System.out.println(); i++; } } }
Enter Right Triangle of Incremented Characters Rows = 13
Right Triangle of Incremented Row Characters Pattern
A
B A
C B A
D C B A
E D C B A
F E D C B A
G F E D C B A
H G F E D C B A
I H G F E D C B A
J I H G F E D C B A
K J I H G F E D C B A
L K J I H G F E D C B A
M L K J I H G F E D C B A
This Java program uses the do while loop to display the right angled triangle pattern of incremental alphabets.
package Alphabets; import java.util.Scanner; public class RightTriIncAlp3 { private static Scanner sc; public static void main(String[] args) { sc = new Scanner(System.in); System.out.print("Enter Right Triangle of Incremented Characters Rows = "); int rows = sc.nextInt(); System.out.println("Right Triangle of Incremented Row Characters Pattern"); int i, j, alphabet = 65; i = 0; do { j = i; do { System.out.print((char)(alphabet + j) + " "); } while(--j >= 0 ); System.out.println(); } while(++i <= rows - 1); } }
Enter Right Triangle of Incremented Characters Rows = 16
Right Triangle of Incremented Row Characters Pattern
A
B A
C B A
D C B A
E D C B A
F E D C B A
G F E D C B A
H G F E D C B A
I H G F E D C B A
J I H G F E D C B A
K J I H G F E D C B A
L K J I H G F E D C B A
M L K J I H G F E D C B A
N M L K J I H G F E D C B A
O N M L K J I H G F E D C B A
P O N M L K J I H G F E D C B A