Print Number Pattern - 8 | Java Programs

Output:

Enter the number of rows: 8

1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

class NumberPattern8 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the number of rows: ");
        int base = scanner.nextInt();
        System.out.println();
        for (int i = base; i > 0; i--) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon