-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStarSign.java
46 lines (38 loc) · 1.23 KB
/
StarSign.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
36
37
38
39
40
41
42
43
44
45
46
public class StarSign {
public static void main(String[] args) {
//The tests are not checking the main, so you can modify it freely.
//NB: If the tests don't seem to pass, you should try the methods here
//in the main to make sure they print the correct shapes!
printStars(3);
System.out.println("\n---"); // printing --- between the shapes
printSquare(4);
System.out.println("\n---");
printRectangle(5, 6);
System.out.println("\n---");
printTriangle(3);
System.out.println("\n---");
}
public static void printStars(int number) {
// first part of the exercise
String stars = "";
for(int i = 0; i < number; i++) {
stars += "*";
}
System.out.println(stars);
}
public static void printSquare(int size) {
for(int i = 0; i < size; i++) {
printStars(size);
}
}
public static void printRectangle(int width, int height) {
for(int i = 0; i < height; i++){
printStars(width);
}
}
public static void printTriangle(int size) {
for(int i = 0; i <= size; i++) {
printStars(i);
}
}
}