In this article, we will discuss the concept of Alphabet triangle pattern using the do-while loop in Java programming language.
We can print various type of number, asterisk, binary patterns using for, while and do-while loop in Java language
In this post, we will discuss how to write a program to print different alphabet triangle pattern using the do-while loop in Java language.
To understand this example programs, you should have previous knowledge of following Java topics
Do while loop in Java language
Nested do while loop in Java language
Program 1
import java.util.Scanner; class AlphabetPatternDoWhile1{ public static void main (String args[]){ int i,j; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows"); //get input from the user to number of rows int rows=scan.nextInt(); i=1; do{//outer loop j=1; do{//inner loop System.out.print((char)(i+64)); j++; }while( j<=i);//End of inner loop System.out.println(); i++; }while( i<=rows);//End of outer loop } }
When the above code is executed, it produces the following results
Program 2
import java.util.Scanner; class AlphabetPatterndowhile2{ public static void main (String args[]){ int i,j; int letter=64; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows"); //Takes input from the user to number of rows int rows=scan.nextInt(); i=1; do{ j=1; do{ System.out.print((char)(j+letter)); j++; }while( j<=i); System.out.println(); i++; }while(i<=rows); } }
When the above code is executed, it produces the following results
Program 3
import java.util.Scanner; class AlphabetPatterndowhile3{ public static void main (String args[]){ int i,j; int letter=64; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows: "); //get input from the user to number of rows int rows=scan.nextInt(); System.out.print("\nYour pattern here\n\n"); i=rows; do{ j=rows; do{ System.out.print((char)(j+letter)); j--; }while( j>=i); System.out.println(); i--; }while(i>=1); } }
When the above code is executed, it produces the following results
Program 4
import java.util.Scanner; class AlphabetPatterndowhile4{ public static void main (String args[]){ int i,j; int letter=64; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows: "); //get input from the user to number of rows int rows=scan.nextInt(); System.out.print("\nYour pattern here\n\n"); i=rows; while(i>=1){ j=1; while(j<=i){ System.out.print((char)(j+letter)); j++; } System.out.println(); i--; } } }
When the above code is executed, it produces the following results
Program 5
import java.util.Scanner; class AlphabetPatterndowhile5{ public static void main (String args[]){ int i,j; int letter=64; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows: "); //get input from the user to number of rows int rows=scan.nextInt(); System.out.print("\nYour pattern here\n\n"); i=1; do{ j=rows; do{ System.out.print((char)(i+letter)); j--; } while(j>=i); System.out.println(); i++; }while(i<=rows); } }
When the above code is executed, it produces the following results
Program 6
import java.util.Scanner; class AlphabetPatterndowhile6{ public static void main (String args[]){ int i,j; int letter=64; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows: "); //get input from the user to number of rows int rows=scan.nextInt(); System.out.print("\nYour pattern here\n\n"); i=rows; do{ j=i; do{ System.out.print((char)(j+letter)); j++; } while(j<=rows); System.out.println(); i--; }while(i>=1); } }
When the above code is executed, it produces the following results
Program 7
import java.util.Scanner; class AlphabetPatterndowhile7{ public static void main (String args[]){ int i,j; int letter=64; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows: "); //get input from the user to number of rows int rows=scan.nextInt(); System.out.print("\nYour pattern here\n\n"); i=1; do{ j=i; do{ System.out.print((char)(j+letter)); j--; }while( j>=1); System.out.println(); i++; }while(i<=rows) } }
When the above code is executed, it produces the following results
Program 8
import java.util.Scanner; class AlphabetPatterndowhile8{ public static void main (String args[]){ int i,j; int letter=64; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows: "); //get input from the user to number of rows int rows=scan.nextInt(); System.out.print("\nYour pattern here\n\n"); i=1; do{ j=1; do{ System.out.print((char)(rows-i+1+letter)); j++; } while( j<=i); System.out.println(); i++; }while(i<=rows); } }
When the above code is executed, it produces the following results
Program 9
import java.util.Scanner; class AlphabetPatterndowhile9{ public static void main (String args[]){ int i,j; int letter=64; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows: "); //get input from the user to number of rows int rows=scan.nextInt(); System.out.print("\nYour pattern here\n\n"); i=rows; do{ j=1; do{ System.out.print((char)(i+letter)); j++; } while( j<=i); System.out.println(); i--; }while(i>=1); } }
When the above code is executed, it produces the following results
Program 10
import java.util.Scanner; class AlphabetPatterndowhile10{ public static void main (String args[]){ int i,j; int letter=64; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows: "); //get input from the user to number of rows int rows=scan.nextInt(); System.out.print("\nYour pattern here\n\n"); i=rows; do{ j=i; do{ System.out.print((char)(j+letter)); j--; }while(j>=1); System.out.println(); i--; }while( i>=1); } }
When the above code is executed, it produces the following results
Program 11
import java.util.Scanner; class AlphabetPatterndowhile11{ public static void main (String args[]){ int i,j,k=1; int letter=64; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows: "); //get input from the user for number of rows int rows=scan.nextInt(); System.out.print("\nYour pattern here\n\n"); i=1; do{ j=1; do{ System.out.print((char)(k+letter)); j++; k++; }while( j<=i); System.out.println(); i++; }while( i<=rows); } }
When the above code is executed, it produces the following results
Program 12
import java.util.Scanner; class AlphabetPatterndowhile12{ public static void main (String args[]){ int i,j,k=1; int letter=64; int num,count; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows: "); //get input from the user for number of rows int rows=scan.nextInt(); System.out.print("\nYour pattern here\n\n"); i=1; do{ num=rows-1; count=i; j=1; do{ System.out.print((char)(count+letter)); count=count+num; num--; j++; }while( j<=i); System.out.println(); i++; }while(i<=rows); } }
When the above code is executed, it produces the following results
Program 13
import java.util.Scanner; class AlphabetPatternDowhile{ public static void main (String args[]){ int i,j,k; int letter=64; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows: "); //get input from the user for number of rows int rows=scan.nextInt(); System.out.print("\nYour pattern here\n\n"); i=rows; while( i>=1){ k=i; j=1; while(j<=i){ System.out.print((char)(k+letter)); j++; k++; } System.out.println(); i--; } } }
When the above code is executed, it produces the following results
Program 14
import java.util.Scanner; class AlphabetPatterndowhilefif{ public static void main (String args[]){ int i,j; int letter=64; Scanner scan=new Scanner(System.in); System.out.print("Enter the number of rows: "); //get input from the user for number of rows int rows=scan.nextInt(); System.out.print("\nYour pattern here\n\n"); i=1; do{ j=i; do{ System.out.print((char)(j+letter)); j++; } while( j<=rows); System.out.println(); i++; }while( i<=rows); } }
When the above code is executed, it produces the following results
Suggested for you
Data type and variable in Java language
Similar post
C code to Alphabet triangle pattern using the do-while loop
C++ code to Alphabet triangle pattern using the do-while loop
Java code to Alphabet triangle pattern using the do-while loop
Alphabet pattern in C language
Alphabet triangle pattern in C language using while loop
Alphabet pattern in Java language
Alphabet triangle pattern in Java language using while loop
Alphabet pattern in C++ language
Alphabet triangle pattern in C++ language using while loop
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…