Computer Science, asked by 12457gsuhdhdzzt, 9 months ago

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 sujayG17
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