Computer Science, asked by meenusingh36, 8 days ago

write a program in java to print following pattern
@
&&
@@@
&&&&
@@@@@

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[]){

       for(int i=1;i<=5;i++){

           for(int j=1;j<=i;j++)

               System.out.print((i%2==0)?"& ":"@ ");

           System.out.println();

       }

   }

}

\textsf{\large{\underline{Logic}:}}

  1. Create a loop and iterate it 5 times.
  2. Check if the row number is odd or not. If true, display '@' or else display '&'.
  3. Print a new line after every row.

See attachment for output.

Attachments:
Similar questions