WRITE A JAVA PROGRAM TO BELOW PATTERN :
A A A A A
B B B B
C C C
D D
E
Answers
Answered by
5
Required Program -
public class Pattern{
public static void main(String args[]){
int n = 5; //For number of rows.
char ch = 'A' ; //char variable for printing the pattern
for(int i =n;i>=1;i--){ //Outer loop
for(int j = 1;j<=i;j++){ //Inner loop
System.out.print(ch); //To print each character.
}
ch++; //Increments the character after one row has been printed.
System.out.println(""); //To go to the next line after row is printed.
}
}
}
Procedure -
- Outer loop is used for each row, inner loop is used to print the characters in each row.
- We use a char variable and keep incrementing it at the end of the outer loop to print the characters.
- Here, the variable n is used for the number of rows i.e. 5 rows.
Output -
=> Refer to attachment for output on bluej IDE .
Attachments:
Similar questions