forked from HarryDulaney/intro-to-java-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExercise05_18.java
80 lines (64 loc) · 1.72 KB
/
Exercise05_18.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package ch_05;
import java.util.*;
/**
* *5.18 (Display four patterns using loops) Use nested loops that display the following
* patterns in four separate programs:
* Pattern A Pattern B Pattern C Pattern D
*/
public class Exercise05_18 {
public static void main(String[] args) {
patternA();
System.out.println();
patternB();
System.out.println();
patternC();
System.out.println();
patternD();
}
static void patternA() {
System.out.println("Pattern A");
int x = 1;
for (int i = 0; i < 6; i++) {
for (int j = 1; j <= x; j++) {
System.out.print(j);
}
System.out.println();
x++;
}
}
static void patternB() {
System.out.println("Pattern B");
int x = 0;
for (int i = 0; i < 6; i++) {
for (int j = 1; j < 7 - x; j++) {
System.out.print(j);
}
System.out.println();
x++;
}
}
static void patternC() {
System.out.println("Pattern C");
for (int i = 1; i <= 6; i++) {
for (int j = 6 - i; j >= 1; j--) {
System.out.print(" ");
}
for (int z = i; z >= 1; z--) {
System.out.print(z);
}
System.out.println();
}
}
static void patternD() {
System.out.println("Pattern D");
for (int i = 0; i < 6; i++) {
for (int z = 0; z < i; z++) {
System.out.print(" ");
}
for (int j = 1; j <= 6 - i; j++) {
System.out.print(j);
}
System.out.println();
}
}
}