Advertisements

Aatul Palandurkar

Pattern Programs in Java – Pattern 2

Posted on: June 11, 2018

Pattern 2 :

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Java Program for the above pattern:


import java.util.Scanner;



public class MainClass

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);



//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");



int rows = sc.nextInt();



System.out.println("Here is your pattern....!!!");



for (int i = 1; i <= rows; i++)

{

for (int j = 1; j <= i; j++)

{

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

}



System.out.println();

}



//Close the resources
sc.close();

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisements

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 13,538 other followers

Tweets

YouTube

Archives

Advertisements
%d bloggers like this: