for(int i=0; i <= n; i++) {
for(int j=i; j > 0; j--) {
System.out.print(j + " ");
}
System.out.println();
}
In the above loops. First loop goes from 0 to n times depending on value of n. Second loop is goes from value of i and keeps looping as long as j > 0.
First loop i=0 prints nothing, for i=1 j prints 1, only once then come out of loop and i become 2 and the inner loop prints 2 and 1 and then comes out of loop and prints new line and i become 3 and then inner loop print 3 and 2 and 1 and then come out of loop and so on.
Put above code in your method TheNum and then call your method passing it value of n that is provided by user as below:
TheNum(n);
Put above function call after the statement that takes the input.
solved Writing a pattern in java [closed]