Write a program in Java to display the following pattern
1
2 3
4 5 6
7 8 9 10
Answers
Answered by
4
Note: Here, I have assumed that the number of rows is fixed.
public class Pattern{
public static void main(String args[]){
for(int i=1,a=1;i<=4;i++){
for(int j=1;j<=i;j++)
System.out.print(a++ +" ");
System.out.println();
}
}
}
1
2 3
4 5 6
7 8 9 10
See attachment for verification.
Attachments:
Answered by
0
Answer:
Program:-
public class Main
{
public static void main(String args[])
{
int i,j,p=1;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
System.out.print(p+" ");
p++;
}
System.out.println();
}
}
}
Attachments:
Similar questions