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();
        }
    }
}

Comments

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

    ReplyDelete

Post a Comment

Popular posts from this blog

Print Number Pattern - 10 | Java Programs

Print your name in Java | Java Programs

Print Number Pattern - 9 | Java Programs