Alphabet Pattern

Alphabet Pyramid pattern in Java using while loop

Alphabet Pyramid pattern in Java using while loop

In this tutorial, we will discuss about Alphabet Pyramid pattern in Java using while loop

Alphabet Pyramid pattern in C using while loop

Alphabet Pyramid pattern in Java

In this program, we are going to learn about how to display  Alphabet pyramid pattern  using while loop  in Java programming language

Here, we display a  Alphabet pyramid pattern program with coding using nested while loop and also we get input from the user using Scanner class  in the  Java language

The user can provide numbers as they wish and get the  Alphabet pyramid pattern according to their input.

Alphabet pyramid pattern 1

Program 1

import java.util.Scanner;//import the scanner class
class PyramidPatternWhile{
public static void main(String args[]){
Scanner scan=new Scanner(System.in);//create a scanner object
System.out.println("Enter the number of rows");
int rows=scan.nextInt();
int i,j;
i=1;
while(i<=rows){
j=1;
  while(j<=rows-i){//print space 
  System.out.print(" ");
  j++;
  }

 
   j=1;
   while(j<=i){//print left site pattern
  System.out.print((char)(j+64));
   j++;
    }

   j=i-1;
   while(j>=1){//print right site pattern
  System.out.print((char)(j+64));
   j--;
}
i++;
System.out.println();
}

}
}

 

When the above code is executed, it produces the following results

Enter the number of rows
6
          A
        ABA
      ABCBA
    ABCDCBA
  ABCDEDCBA
ABCDEFEDCBA

Alphabet pyramid pattern 2

Program 2

import java.util.Scanner;//import the scanner class
class PyramidPatternWhile1{
public static void main(String args[]){
Scanner scan=new Scanner(System.in);//create a scanner object
System.out.println("Enter the number of rows");
int rows=scan.nextInt();
int i,j;
i=1;
while(i<=rows){//outer while loop
j=1;
  while(j<=rows-i){//inner while loop 1
  System.out.print(" ");//prinet space
  j++;
  }

 
   j=i;
   while(j>0){//inner while loop 2
  System.out.print((char)(j+64));//print left site pattern
   j--;
    }

   j=2;
   while(j<=i){//print right side pattern
  System.out.print((char)(j+64));
   j++;
}
i++;
System.out.println();
}

}
}

 

When the above code is executed, it produces the following results

Enter the number of rows
6
          A
        BAB
      CBABC
    DCBABCD
  EDCBABCDE
FEDCBABCDEF

Alphabet pyramid pattern 3

Program 3

import java.util.Scanner;//import the scanner class
class PyramidPatternWhile2{
public static void main(String args[]){
Scanner scan=new Scanner(System.in);//create a scanner object
System.out.println("Enter the number of rows");
int rows=scan.nextInt();
int i,j;
i=1;
while(i<=rows){
j=1;
  while(j<=rows-i){
  System.out.print(" ");
  j++;
  }

 
   j=1;
   while(j<=i){
  System.out.print((char)(char)(j+64)+" ");
   j++;
    }
    i++;
    System.out.println();
}

}

}

When the above code is executed, it produces the following results

Enter the number of rows
5
        A
      A B
    A B C
  A B C D
A B C D E

Alphabet pyramid pattern 4

Program 4

import java.util.Scanner;//import the scanner class
class PyramidPatternWhile3{
public static void main(String args[]){
Scanner scan=new Scanner(System.in);//create a scanner object
System.out.println("Enter the number of rows");
int rows=scan.nextInt();
int i,j;
i=1;
while(i<=rows){
j=1;
  while(j<=rows-i){
  System.out.print(" ");
  j++;
  }

 
   j=1;
   while(j<=i){
  System.out.print((char)(char)(i+64)+" ");
   j++;
    }
    i++;
    System.out.println();
}

}

}

 

When the above code is executed, it produces the following results

Enter the number of rows
6
          A
        B B
      C C C
    D D D D
   E E E E E
  F F F F F F

Alphabet pyramid pattern 5

Program 5

import java.util.Scanner;//import the scanner class
class PyramidPatternWhile4{
public static void main(String args[]){
Scanner scan=new Scanner(System.in);//create a scanner object
System.out.println("Enter the number of rows");
int rows=scan.nextInt();
int i,j;
i=rows;
while(i>=1){
j=1;
  while(j<=rows-i){
  System.out.print("  ");
  j++;
  }

 
   j=1;
   while(j<=2*i-1){
       if(j<=i)
  System.out.print((char)(char)(j+64)+" ");
      else
          System.out.print((char)(char)(2*i-j+64)+" ");
   j++;
    }
    i--;
    System.out.println();
}

}

}

 

When the above code is executed, it produces the following results

Enter the  number of rows
5
A B C D E D C B A
    A B C D C B A
        A B C B A
            A B A
                A

 

Suggested for you

Operator in Java language

Data type  in Java language

While loop in Java language

Nested while loop in Java language

 

 

 

Cpp program to display Binary pyramid pattern
Cpp program to generate Alphabet pyramid
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

View Comments

    • import java.util.Scanner;
      class SquarePattern1{
      public static void main(String args[]){
      int i,j,k; //variable declaration
      Scanner scan=new Scanner(System.in);
      //create a scanner object for input
      //get input from the user for rows
      System.out.print("Enter the number of rows: ");
      int rows=scan.nextInt();
      System.out.print("\n");
      int count=0;
      /*Print this pattern
      5 5 5 5 5
      5 4 4 4 4
      5 4 3 3 3
      5 4 3 2 2
      5 4 3 2 1*/
      for(i=rows; i>=1; i--){
      for(j=rows; j>=i; j--){
      System.out.print(j+" ");
      count=j;
      }
      for(k=rows-i+1; k

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

10 hours ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago