Print Number Pattern - 4 | Java Programs

Output:

Enter the number of rows: 8

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

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

class NumberPattern4 {

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

Related Post



sentiment_satisfied Emoticon