Printing Pyramid with Increasing Character Pattern
In this program we are going to see how to print the triangle with increasing character pattern.
Let’s see the example first.
Example-1 When row value=6 A A B A B C A B C D A B C D E A B C D E F
Example-2: When row value=5 A A B A B C A B C D A B C D E
Now, let’s see the actual program to print it.
If you are new to Java and want to learn the java coding skills too fast. Try practicing the core java programs with the help of the Java basic programs list available.
Approach:
- Enter the character and store it in a variable
c
. - Then enter total row and store it in an integer variable
row_count
. - Take one outer for loop to iterate the rows.
- Take one inner loop to iterate the columns and print the character.
- After each iteration print a new line.
JAVA CODE:
import java.util.*; public class Main { public static void main(String[] args) { // Scannr class object created Scanner scan = new Scanner(System.in); //Taking number of rows as //input from the user System.out.print("Rows : "); int row_count = scan.nextInt(); // for loop to print the number of rows for (int row = 0; row <= row_count; row++) { int c = 65; // for loop to print the column values // here printing space for (int col = 5; col > row; col--) { System.out.print(" "); } // for loop to print the column values // here printing the character value for (int k = 0; k < row; k++) { System.out.print((char) (c + k) + " "); } // one row printing completed // moving to the next line System.out.println(); } } }
Output: Rows: 5 A A B A B C A B C D A B C D E
Related Java Star Pattern Programs:
- Java Program to Print Right Angled Triangle with Repeating Character (Increasing Order) Pattern
- Java Program to Print Right Angled Triangle with Repeating Character (Decreasing Order) Pattern
- Java Program to Print Right Angled Triangle with Column Wise Increasing Character Pattern
- Java Program to Print Right Angled Triangle with Row wise Decreasing Character Pattern
- Java Program to Print Right Angled Triangle with Row wise Increasing Character Pattern