-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleStar.java
More file actions
40 lines (36 loc) · 1.13 KB
/
SimpleStar.java
File metadata and controls
40 lines (36 loc) · 1.13 KB
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
36
37
38
39
40
import java.util.Scanner;
/**
* @author Divyam (https://github.com/DevYam)
* @created 24/08/2020 - 09:43
* @project java
*/
public class SimpleStar {
public static void main(String[] args) {
System.out.println("Enter the number of rows you want in your star pattern");
Scanner sc = new Scanner(System.in);
int row = Integer.parseInt(sc.nextLine());
System.out.println("Choose the orientation of star pyramid :\n1. Upright \n2. Inverted");
int orientation = Integer.parseInt(sc.nextLine());
if (orientation == 1) {
upright(row);
} else {
inverted(row);
}
}
public static void upright(int numberOfRows){
for (int i = 0; i <numberOfRows ; i++) {
for (int j = 0; j <i ; j++) {
System.out.print("*");
}
System.out.println();
}
}
public static void inverted(int numberOfRows){
for (int i = numberOfRows; i >0 ; i--) {
for (int j = 0; j <i ; j++) {
System.out.print("*");
}
System.out.println();
}
}
}