
Write a test program that read an integer n and call a method to display a pattern as follows: 1 2 1 3 2 1 4 3 2 1 ... n n-1 ... 3 2 1 The method header is public static void displayPattern(int n)

Here is a code that displays the following pattern:
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
class Pattern{
public static void displayPattern(int n){
for(int i=1;i<=n;i++){
for(int j=i;j>=1;j--){
System.out.print(j);
}
System.out.println();
}
}
public static void main(String args[]){
displayPattern(5);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.