Print Number Pattern - 7 | Java Programs

Output:

Enter the number of rows: 8

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

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

class NumberPattern7 {

    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 j = base; j > 0; j--) {
            for (int i = base; i >= j; i--) {

                System.out.print(i + " ");
            }
            System.out.println();
        }
    }
}
Share This :

Related Post

avatar

nice article.thank you for sharing useful info.
visit
web programming tutorial
welookups

delete 29 August 2018 at 20:12



sentiment_satisfied Emoticon