In this tutorial, we will write a program to display half alphabet pyramid patterns in java. Before that, you may go through the following topic in java.
Example:
1 2 3 4 5 6 7 | Rows Input: 5 Output: A A B A B C A B C D A B C D E |
This program is also known as right-angled triangle patterns using the alphabet in java as the right angle is formed on the right side of the pattern.
Java Program to print Half Pyramid using Alphabets
The program takes a user input for the number of rows to be displayed on the screen. The Alphabet starts from A and increases at every row such as A, Ab, ABC, and so on.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import java.util.Scanner; public class Main { public static void main(String args[]) { int rows, i, j; char ch; Scanner scan = new Scanner(System.in); System.out.print("Enter the number of rows: "); rows = scan.nextInt(); System.out.print("Output:\n"); for (i = 1; i <= rows; i++) { ch = 'A'; for (j = 1; j <= i; j++) { System.out.print(" " + ch++); } System.out.print("\n"); } } } |
Output:
1 2 3 4 5 6 7 8 9 | Enter the number of rows: 7 Output: A A B A B C A B C D A B C D E A B C D E F A B C D E F G |