program for nested loop 1 21 321 4321 54321
Answers
Answered by
3
Answer:
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.util.Scanner;
public class Pattern {
public static void printPattern(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) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = scanner.nextInt();
printPattern(n);
}
}
Here is a sample output :
1
2
3
4
5
6
Enter a number: 5
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
Similar questions
Math,
5 months ago
Math,
5 months ago
Social Sciences,
5 months ago
Biology,
10 months ago
Political Science,
1 year ago