-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignmentSix
More file actions
96 lines (86 loc) · 1.88 KB
/
AssignmentSix
File metadata and controls
96 lines (86 loc) · 1.88 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import javax.swing.JOptionPane;
/* You must write the methods doOne, doTwo, doThree, doFour and doFive
* to produce the patterns that my code produced.
*
* Each method may have at most one occurrence of
* System.out.print("*")
* System.out.print(" ")
* System.out.println()
*
* You will need to use for or while loops to produce the desired
* output.
*/
public class AssignmentSix {
public static void main(String[] args) {
int n = Integer.parseInt(JOptionPane.showInputDialog("Enter n"));
System.out.println("\nn == " + n);
doOne(n, "\nPattern 1");
doTwo(n, "\nPattern 2");
doThree(n, "\nPattern 3");
doFour(n, "\nPattern 4");
doFive(n, "\nPattern 5");
}
private static void doOne(int n, String title) {
System.out.println(title);
for (int i = 0; i < n; i++)
{
for (int ii = 0; ii<=i; ii++)
{
System.out.print("*");
}
System.out.println();
}
}
private static void doTwo(int n, String title) {
System.out.println(title);
for (int i = n; i > 0; i--)
{
for (int ii=i; ii>0; ii--)
{
System.out.print("*");
}
System.out.println();
}
}
private static void doThree(int n, String title) {
if (title.equals("\nPattern 3"))
{
System.out.println(title);
}
for (int i = 0; i < n; i +=2 )
{
for (int j = i; j < n-1; j+=2 )
{
System.out.print(" ");
}
for (int k = 0; k <= i; k++)
{
System.out.print("*");
}
System.out.println();
}
}
private static void doFour(int n, String title) {
if (title.equals("\nPattern 4"))
{
System.out.println(title);
}
for (int i = n; i > 0; i-=2 )
{
for (int j = n; j > i; j-=2 )
{
System.out.print(" ");
}
for (int ii = i; ii > 0; ii-- )
{
System.out.print("*");
}
System.out.println();
}
}
private static void doFive(int n, String title) {
System.out.println(title);
doThree(n, title);
doFour(n, title);
}
}