Codeforcoding

Java code to triangle alphabet pattern using while loop

Java code to triangle alphabet pattern using while loop

In this tutorial, we will discuss Java code to triangle alphabet pattern using while loop

In this post, we will learn how to displayed  Floyd’s triangle alphabet pattern  using while loop or nested while loop in Java programming language

here, we displayed some alphabet Floyd’s triangle program with coding using nested while loop and also we get input from user using Scanner class  in Java language

Java code to triangle alphabet pattern using while loop
Pattern programs

the user can provide numbers as they wish and get the alphabet pattern according to their input

 

Triangle alphabet pattern 1

Program 1

import java.util.Scanner;//import the scanner class
class patternWhile1{
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<=i){
        System.out.print((char)(i+64));
        j++;
    }
    i++;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
A
BB
CCC
DDDD
EEEEE
FFFFFF

 

Triangle alphabet pattern 2

Program 2

import java.util.Scanner;//import the scanner class
class PatternWhile2{
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<=i){
        System.out.print((char)(j+64));
        j++;
    }
    i++;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
A
AB
ABC
ABCD
ABCDE
ABCDEF

 

Triangle alphabet pattern 3

Program 3

import java.util.Scanner;//import the scanner class
class PatternWhile3{
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=i;
    while(j<=rows){
        System.out.print((char)(i+64));
        j++;
    }
    i++;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
AAAAAA
BBBBB
CCCC
DDD
EE
F

Triangle alphabet pattern 4

Program 4

import java.util.Scanner;//import the scanner class
class PatternWhile4{
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=i;
    while(j<=rows){
        System.out.print((char)(j+64));
        j++;
    }
    i++;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
ABCDEF
BCDEF
CDEF
DEF
EF
F

 

Triangle alphabet pattern 5

Program 5

import java.util.Scanner;//import the scanner class
class PatternWhile5{
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=i;
    while(j<=rows){
        System.out.print((char)(j+64));
        j++;
    }
    i--;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
F
EF
DEF
CDEF
BCDEF
ABCDEF

Triangle alphabet pattern 6

Program 6

import java.util.Scanner;//import the scanner class
class PatternWhile6{
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=i;
    while(j>=1){
        System.out.print((char)(j+64));
        j--;
    }
    i++;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
A
BA
CBA
DCBA
EDCBA
FEDCBA

 

Triangle alphabet pattern 7

Program 7

import java.util.Scanner;//import the scanner class
class PatternWhile7{
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=rows;
    while(j>=i){
        System.out.print((char)(j+64));
        j--;
    }
    i--;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
F
FE
FED
FEDC
FEDCB
FEDCBA

 

Triangle alphabet pattern 8

Program 8

import java.util.Scanner;//import the scanner class
class PatternWhile8{
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<=i){
        System.out.print((char)(rows-i+1+64));
        j++;
    }
    i++;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
F
EE
DDD
CCCC
BBBBB
AAAAAA

 

Triangle alphabet pattern 9

Program 9

import java.util.Scanner;//import the scanner class
class PatternWhile9{
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<=i){
        System.out.print((char)(i+64));
        j++;
    }
    i--;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
FFFFFF
EEEEE
DDDD
CCC
BB
A

 

 

Triangle alphabet pattern 10

Program 10

import java.util.Scanner;//import the scanner class
class PatternWhile10{
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=rows;
    while(j>=i){
        System.out.print((char)(j+64));
        j--;
    }
    i++;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
FEDCBA
FEDCB
FEDC
FED
FE
F

Triangle alphabet pattern 11

Program 11

import java.util.Scanner;//import the scanner class
class PatternWhile11{
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=i;
    while(j>=1){
        System.out.print((char)(j+64));
        j--;
    }
    i--;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
FEDCBA
EDCBA
DCBA
CBA
BA
A

Triangle alphabet pattern 12

Program 12

import java.util.Scanner;//import the scanner class
class PatternWhile12{
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=i;
    while(j<=rows){
        System.out.print((char)(j+64)+(" "));
        j++;
    }
    i++;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

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

Triangle alphabet pattern 13

Program 13

import java.util.Scanner;//import the scanner class
class PatternWhile13{
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=i;
    while(j>=1){
        System.out.print((char)(j+64)+(" "));
        j--;
    }
    i++;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

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

Triangle alphabet pattern 14

Program 14

import java.util.Scanner;//import the scanner class
class PatternWhile14{
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=i;
    while(j>=1){
        System.out.print((char)(j+64)+(" "));
        j--;
    }
    i--;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

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

Triangle alphabet pattern 15

Program 15

import java.util.Scanner;//import the scanner class
class PatternWhile15{
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,num,count;
i=1;
while(i<=rows){
    num=rows-1;
    count=i;
    
    j=1;
    while(j<=i){
        System.out.print((char)(count+64)+(" "));
        count=count+num;
        num--;
        j++;
    }
    i++;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
A 
B G
C H L
D I M P
E J N Q S
F K O R T U

Triangle alphabet pattern 16

Program 16

import java.util.Scanner;//import the scanner class
class PatternWhile16{
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,num,count;
i=1;
while(i<=rows){
    
    j=1;
    while(j<=(i*2-1)){
        System.out.print((char)(j+64)+(" "));
        j++;
    }
    i++;
    System.out.println();
}
}
}

When the above code executed, it produces the following results

Enter the number of rows
6
A
A B C
A B C D E
A B C D E F G 
A B C D E F G H I
A B C D E F G H I J K

 

Suggested for you

Operator in Java

While loop in  Java

Nested while loop in Java

 Data type in Java

Cpp program triangle alphabet pattern using while loop
C program to Floyd's triangle binary pattern
Exit mobile version