Follow on Facebook

Like and Share on Facebook

Showing posts with label Java Programs to print pattern 12345 22345 33345 44445 55555. Show all posts
Showing posts with label Java Programs to print pattern 12345 22345 33345 44445 55555. Show all posts

Thursday, December 18, 2014

Java Programs to print pattern 12345 22345 33345 44445 55555




import java.util.Scanner;


public class Pattern {


    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter n: ");

        int n = scanner.nextInt();

        for (int i = 1; i <= n; i++) {

            for (int j = 1; j <= n; j++) {

                if (j <= i) {

                    System.out.print(i + " ");

                } else {

                    System.out.print(j + " ");

                }

            }

            System.out.println();

        }

    }

Output:

12345
22345
33345
44445
55555