Print Number Pattern - 1 | Java Programs

Output:

Enter the number of rows: 9
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 6 7 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8 9

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

class NumberPattern1 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the number of rows: ");
        int base = scanner.nextInt();
        int it = 1;
        for (int a = 1; a <= base; a++) {
            for (it = 1; it <= a; it++) {
                System.out.print(it + " ");
            }
            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:11



sentiment_satisfied Emoticon