Write a program in java to enter the number of rows(n) and display the following pattern:(if n=6)
1
3 2
4 5 6
10 9 8 7
11 12 13 14 15
21 20 19 18 17 16
Answers
Answered by
1
public class example
{
public static void main (String [] args)
{
int n = 6;
int x = 1;
for(int i = 1; i<=n; i++)
{
for(int j = 1; j<=i; j++)
{
System.out.print(x);
x++;
}
}
System.out.println();
}
}
Please do this in your Java compiler and inform whether it is correct or not. Hope this helps you.
Similar questions
Computer Science,
4 months ago
Math,
4 months ago
Physics,
9 months ago
Science,
9 months ago
Physics,
1 year ago