Skip to content

Commit 8311a0e

Browse files
committed
Initial commit
1 parent 0911cea commit 8311a0e

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Pattern-2/Star_Pattern.java

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Print the following pattern
3+
Pattern for N = 4
4+
5+
*
6+
***
7+
*****
8+
*******
9+
*/
10+
11+
import java.util.Scanner;
12+
13+
public class Star_Pattern {
14+
public static void main(String[] args) {
15+
16+
/*
17+
* Your class should be named Solution.
18+
* Read input as specified in the question.
19+
* Print output as specified in the question.
20+
*/
21+
22+
Scanner sc = new Scanner(System.in);
23+
int n = sc.nextInt();
24+
int space = n - 1;
25+
int i = 1;
26+
while (i <= n) {
27+
int j = 1;
28+
space = n - i;
29+
while (space > 0) {
30+
System.out.print(" ");
31+
space--;
32+
}
33+
while (j <= ((2 * i) - 1)) {
34+
System.out.print("*");
35+
j += 1;
36+
}
37+
System.out.println("");
38+
i += 1;
39+
}
40+
41+
}
42+
43+
}

0 commit comments

Comments
 (0)