forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pattern.java
35 lines (29 loc) · 883 Bytes
/
Pattern.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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 = i; j < rows ; j++) {
System.out.print(" ");
}
for (int k = 1; k <= (2*i -1) ;k++) {
if( k==1 || i == rows || k==(2*i-1)) {
System.out.print("*");
}
else {
System.out.print(" ");
}
}
System.out.println("");
}
//Close the resources
sc.close();
}
}