In the program the following pattern will be printed.
A
ABA
ABCBA
ABCDBCA
ABCDEDCBA
The program is shown below :
import java.util.*;
class pattern7
{
public static void main(String args[])
{
Scanner scr=new Scanner(System.in);
int n;
System.out.println("Enter the number of rows. ");
n=scr.nextInt();
char c;
for(int i=1;i<=n;++i) // FOR LOOP FOR NUMBER OF ROWS
{
c='A';
for(int j=i;j
{
System.out.print(" ");
}
for(int k=1;k<=i;++k) // FOR LOOP FOR PRINTING ALPHABETS IN DESCENDING ORDER
{
System.out.print(c);
++c;
}
c-=2;
for(int l=1;l
{
System.out.print(c);
--c;
}
System.out.println(); // INTRODUCING NEW LINE
}
} // end of main method
} // end of main class
OUTPUT
C:\Users\Ravi\Desktop\ravi>javac pattern7.java
C:\Users\Ravi\Desktop\ravi>java pattern7
Enter the number of rows.
6
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
No comments:
Post a Comment