Que 1. Write a Java program to display the following pattern as the output:
Attachments:
Answers
Answered by
7
The given problem is solved using language - Java.
public class Main{
public static void main(String args[]){
int i,j,n=5;
char ch;
System.out.println("Here is your pattern!!\n");
for(i=1;i<=n;i++){
for(j=1;j<=n-i;j++)
System.out.print(" ");
for(ch='A';ch<'A'+i;ch++)
System.out.print(ch+" ");
System.out.println();
}
}
}
- There are (n - i) spaces in each line where n is the number of rows (equal to 5) and 'i' is the row number.
- At first, spaces are added. Then, the characters are added using another loop.
- At the last, a new line is added.
See attachment for output.
Attachments:
Similar questions