In this tutorial, we will write a program to display a right-angle triangle pattern in java using the alphabet. Before that, you may go through the following topic in java.
The program below takes the user input from the user for the number of rows and display the right triangle character pattern in various character orders.
Right angled triangle pattern
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import java.util.Scanner; public class Main { public static void main(String args[]) { int rows, i, j; int ch = 64; Scanner sc = new Scanner(System.in); System.out.print("Enter the number of rows: "); rows = sc.nextInt(); System.out.print("Output:\n"); for (i = rows; i >= 1; i--) { for (j = rows; j >= i; j--) System.out.print((char)(j + ch)+" "); System.out.println(); } } } |
Output:
Enter the number of rows: 5
Output:
E
E D
E D C
E D C B
E D C B A