write a program to display the following pattern. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
Don't spam
Answers
Answered by
1
Answer:
Java Programs to print pattern 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
import java.util.Scanner;
public class Pattern {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter n: ");
int n = scanner.nextInt();
int currentNumber = (int) (n * (n + 1) / 2);
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
System.out.print(currentNumber + " ");
currentNumber--;
}
System.out.println();
}
}
}
Output
Enter n: 5
15 14 13 12 11
10 9 8 7
6 5 4
Similar questions
Geography,
1 month ago
Physics,
1 month ago
Psychology,
3 months ago
Computer Science,
3 months ago
Math,
10 months ago
Math,
10 months ago