Computer Science, asked by nmalang, 2 days ago

Que 1. Write a Java program to display the following pattern as the output:

Attachments:

Answers

Answered by anindyaadhikari13
7

\textsf{\large{\underline{Solution}:}}

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();

       }

   }

}

\textsf{\large{\underline{Explanation}:}}

  • 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