write a program in java to print following pattern
@
&&
@@@
&&&&
@@@@@
Answers
Answered by
7
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();
}
}
}
- Create a loop and iterate it 5 times.
- Check if the row number is odd or not. If true, display '@' or else display '&'.
- Print a new line after every row.
See attachment for output.
Attachments:
Similar questions
Physics,
4 days ago
Social Sciences,
4 days ago
Geography,
8 days ago
English,
8 days ago
English,
8 months ago
Social Sciences,
8 months ago
Math,
8 months ago