Print Number Pattern - 2 | Java Programs

Output:

Enter the number of rows: 8

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

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

class NumberPattern2 {

    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();
        int it = 1;
        for (int a = 1; a <= base; a++) {
            for (it = a; it >= 1; it--) {
                System.out.print(it + " ");
            }
            System.out.println();
        }
    }
}
Share This :

Related Post



sentiment_satisfied Emoticon