-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatternPrint.java
More file actions
78 lines (56 loc) · 1.56 KB
/
patternPrint.java
File metadata and controls
78 lines (56 loc) · 1.56 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
package challanges;
import java.util.Scanner;
public class patternPrint {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome to Print Pattern");
System.out.print("Enter how much row print pattern: ");
int userRow = input.nextInt();
rightHalfPyramid(userRow);
System.out.println();
reverseRightHalfPyramid(userRow);
System.out.println();
leftHalfPyramid(userRow);
}
public static void rightHalfPyramid(int row){
int i = 0;
while (i < row) {
int j = 0;
while (j <= i) {
System.out.print("* ");
j++;
}
System.out.println();
i++;
}
}
public static void reverseRightHalfPyramid(int row){
int i = 0;
while (i < row) {
int starCounter = 0;
while (starCounter < (row - i) ) {
System.out.print("* ");
starCounter++;
}
System.out.println();
i++;
}
}
public static void leftHalfPyramid(int row){
int i = 0;
while (i < row) {
int space = 0;
while (space < (row-i-1)) {
System.out.print(" ");
space++;
}
int star = 0;
while (star <= i) {
System.out.print("*");
star++;
}
System.out.println();
i++;
}
}
}