-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrinting.java
59 lines (52 loc) · 1.54 KB
/
Printing.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
47
48
49
50
51
52
53
54
55
56
57
58
59
public class Printing {
public static void printStars(int amount) {
// 39.1
// you can print one star with the command
// System.out.print("*");
// call this command amount times
int counter = 1;
while (counter <= amount){
System.out.print("*");
counter++;
}
System.out.println();
// System.out.println("\n");
}
public static void printSquare(int sideSize) {
int counter = 1;
while (counter <= sideSize){
printStars(sideSize);
counter++;
}
// 39.2
}
public static void printRectangle(int width, int height) {
int maxHeight = 1;
while (maxHeight <= height){
printStars(width);
maxHeight++;
}
// 39.3
}
public static void printTriangle(int size) {
int counter = 1;
while (counter <= size){
printStars(counter);
counter++;
}
// 39.4
}
public static void main(String[] args) {
// Tests do not use main, yo can write code here freely!
// if you have problems with tests, please try out first
// here to see that the printout looks correct
printStars(3);
System.out.println("\n---"); // printing --- to separate the figures
printSquare(4);
System.out.println("\n---");
printRectangle(5, 6);
System.out.println("\n---");
printTriangle(3);
System.out.println("\n---");
}
}