Print Number Pattern - 10 | Java Programs

Output:

Enter number of basic rows: 6

1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
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 NumberPattern10 {

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

Related Post



sentiment_satisfied Emoticon