Write a java program to display the following patterns.
Input: 7
Output:
7 6 5 4 3 2 1
7 6 5 4 3 2
7 6 5 4 3
7 6 5 4
7 6 5
7 6
7
import java.io.*; import java.util.*; public class temp{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n; System.out.println("Enter a number: "); n= scan.nextInt(); for(int i=1;i<=n;i++){ for (int j=i,p=n; j<=n;j++,p--){ System.out.print(p+" " ); } System.out.println(); } } }
INPUT_1:
Enter a number:
4
OUTPUT:
4 3 2 1
4 3 2
4 3
4
INPUT_2:
Enter a number:
6
OUTPUT:
6 5 4 3 2 1
6 5 4 3 2
6 5 4 3
6 5 4
6 5
6
INPUT_3:
Enter a number:
7
OUTPUT:
7 6 5 4 3 2 1
7 6 5 4 3 2
7 6 5 4 3
7 6 5 4
7 6 5
7 6
7
INPUT_4:
Enter a number:
5
OUTPUT:
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
INPUT_5:
Enter a number:
10
OUTPUT:
10 9 8 7 6 5 4 3 2 1
10 9 8 7 6 5 4 3 2
10 9 8 7 6 5 4 3
10 9 8 7 6 5 4
10 9 8 7 6 5
10 9 8 7 6
10 9 8 7
10 9 8
10 9
10
INPUT_6:
Enter a number:
15
OUTPUT:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2
15 14 13 12 11 10 9 8 7 6 5 4 3
15 14 13 12 11 10 9 8 7 6 5 4
15 14 13 12 11 10 9 8 7 6 5
15 14 13 12 11 10 9 8 7 6
15 14 13 12 11 10 9 8 7
15 14 13 12 11 10 9 8
15 14 13 12 11 10 9
15 14 13 12 11 10
15 14 13 12 11
15 14 13 12
15 14 13
15 14
15
ILLUSTRATION