Java Program to Print Ladder Character Pattern

Program to Print Ladder Character Pattern

In the previous article, we have discussed Java Program to Print Sierpinski Triangle Character Pattern

In this article we are going to see how to print ladder character pattern.

Example-1

When row value= 2

A       A
A       A
AAAAA
B        B
B        B
B BBB B
C        C
C        C
Example-2:

When row value=3

A       A
A       A
AAAAA 
B        B
B        B
B BBB B 
C        C
C        C
C CCC C
D        D
D        D

Now, let’s see the actual program printing  it.

Access the Simple Java program for Interview examples with output from our page and impress your interviewer panel with your coding skills.

Approach to Print Ladder Character Pattern

  • Enter total row and store it in an integer variable row.
  • Take first for loop to cover height of the ladder means all the rows.
  • For each iteration print 2 side character.
  • And for each condition (r<row) print the stair bar.
  • Then go on printing the characters according to loop.

Java Code to Print Ladder Character Pattern

import java.util.*;
public class Main 
{    
    public static void main(String args[])   
    {   
    // taking variable for loop iteration and row .
    int row,r;
    // starting ASCII value taken 65 means 'A'
    int ascii=65;
    //creating object of scanner class
    Scanner s = new Scanner(System.in);
    // entering the number of row
    System.out.print("Enter rows : ");
    row = s.nextInt();
    //outer for loop 
    //To iterate all the rows
    for ( r = 0; r <= row ; r++)
    {
         // Printing the sub-pattern 1 row+1 times
         //two vertical bars are getting printed
        System.out.println((char)(r+ascii)+"   "+(char)(r+ascii));
        System.out.println((char)(r+ascii)+"   "+(char)(r+ascii));
        // Printing the sub-pattern 2 row times
        // middle rows of ladder are getting printed
        if (r < row)
            System.out.println((char)(r+ascii)+""+(char)(r+ascii)+""+
            (char)(r+ascii)+""+(char)(r+ascii)+""+(char)(r+ascii));
    }
  }
}
Output:

Enter rows : 3 

A       A
A       A
AAAAA 
B        B
B        B
B BBB B 
C        C
C        C
C CCC C
D        D
D        D

Are you seeking professional help for coding in the Java programming language? The tutorial of Java Programming Examples for beginners and experts will strongly improve your coding skills then you can program for any logic in Java.

Related Java Character Pattern Programs: