10987 456 32 1
Basic knowledge of Java language and loops.
1. Take the number of rows (n) as input from the user. This will determine the height of the inverted triangle.
2. Initialize a variable (let's call it 'num') to 10. This variable will be used to print the numbers in the pattern, starting from 10.
3. Initialize a loop that runs from n down to 1 (inclusive) to iterate through each row.
4. For each row (let's call the current row index 'i'), initialize another loop that runs from 1 to 'i' (inclusive) to print the numbers in that row.
5. Inside the inner loop, print the current value of 'num', and then decrement 'num' by 1.
6. After finishing the inner loop for a row, print a newline character to move to the next row.
7. Repeat steps 3 to 6 until all rows are printed.
import java.util.Scanner; public class InvertedRightTriangleNumberPattern { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the number of rows for the inverted right triangle number pattern:"); int n = scanner.nextInt(); // Taking input for number of rows int num = 10; // Starting number // Loop to print the inverted right triangle number pattern for (int i = n; i >= 1; i--) { // Loop for each row for (int j = 1; j <= i; j++) { // Loop for each column in the current row System.out.print(num); // Printing the current number num--; // Decrementing the number } System.out.println(); // New line after each row } scanner.close(); } }
Enter the number of rows for the inverted right triangle number pattern: 4 10987 456 32 1