Skip to content

Commit cb8452c

Browse files
committed
completed 9/25 patterns
1 parent f065db2 commit cb8452c

9 files changed

+191
-0
lines changed

Patterns/FullSquare.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class FullSquare {
2+
public static void main(String[] args) {
3+
int i, j;
4+
int size = 10;
5+
char c = '*';
6+
7+
for(i=0; i<size; i++){
8+
for(j=0; j<size; j++){
9+
System.out.print(c+" ");
10+
}
11+
System.out.println();
12+
}
13+
}
14+
}

Patterns/HollowSquare.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class HollowSquare {
2+
public static void main(String[] args) {
3+
int i, j;
4+
int size = 10; // size should >=2
5+
char c = '*';
6+
7+
// top part
8+
for(i=0; i<size; i++){
9+
System.out.print(c+" ");
10+
}
11+
// center part
12+
for(i=0; i<size-2; i++){
13+
System.out.print("\n"+c);
14+
for(j=1; j<(size*2)-2; j++){
15+
System.out.print(" ");
16+
}
17+
System.out.print(c);
18+
}
19+
System.out.println();
20+
// bottom
21+
for(i=0; i<size; i++){
22+
System.out.print(c+" ");
23+
}
24+
System.out.println();
25+
}
26+
}

Patterns/K.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
public class K {
2+
public static void main(String[] args) {
3+
4+
char c = '*';
5+
int limit = 10;
6+
7+
// reverse
8+
for (int i = limit; i > 1; i--) {
9+
for (int j = 1; j < i; j++) {
10+
System.out.print(c+" ");
11+
}
12+
System.out.println();
13+
}
14+
// forward
15+
for (int i = 3; i < (limit + 1); i++) {
16+
for (int j = 1; j < i; j++) {
17+
System.out.print(c+" ");
18+
}
19+
System.out.println();
20+
}
21+
22+
}
23+
}
24+
25+
/* Expected output */
26+
// * * * *
27+
// * * *
28+
// * *
29+
// *
30+
// * *
31+
// * * *
32+
// * * * *

Patterns/NumberChangingPyramid.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class NumberChangingPyramid {
2+
public static void main(String[] args) {
3+
int limit = 10;
4+
int current_int = 1;
5+
6+
for (int i = 1; i <= limit; i++) {
7+
for (int j = 1; j <= i; j++) {
8+
System.out.print(current_int+" ");
9+
current_int++;
10+
}
11+
System.out.println();
12+
}
13+
14+
}
15+
}
16+
17+
/* Expected output */
18+
// 1
19+
// 2 3
20+
// 4 5 6
21+
// 7 8 9 10

Patterns/NumberIncreasingPyramid.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class NumberIncreasingPyramid {
2+
public static void main(String[] args) {
3+
int limit = 10;
4+
5+
for (int i = 1; i <= limit; i++) {
6+
for (int j = 1; j <= i; j++) {
7+
System.out.print(j+" ");
8+
}
9+
System.out.println();
10+
}
11+
12+
}
13+
}
14+
15+
/* Expected output */
16+
// 1
17+
// 1 2
18+
// 1 2 3
19+
// 1 2 3 4
20+
// 1 2 3 4 5
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class NumberIncreasingReversePyramid {
2+
public static void main(String[] args) {
3+
int limit = 10;
4+
5+
for (int i = limit; i >= 1; i--) {
6+
for (int j = 1; j <= i; j++) {
7+
System.out.print(j+" ");
8+
}
9+
System.out.println();
10+
}
11+
12+
}
13+
}
14+
15+
/* Expected output */
16+
// 1 2 3 4 5
17+
// 1 2 3 4
18+
// 1 2 3
19+
// 1 2
20+
// 1

Patterns/ReverseRightHalfPyramid.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class ReverseRightHalfPyramid {
2+
public static void main(String[] args) {
3+
char c = '*';
4+
int limit = 10;
5+
6+
for (int i = limit; i >= 1; i--) {
7+
for (int j = 1; j <= i; j++) {
8+
System.out.print(c+" ");
9+
}
10+
System.out.println();
11+
}
12+
13+
}
14+
}
15+
16+
/* Expected output */
17+
// * * * * *
18+
// * * * *
19+
// * * *
20+
// * *
21+
// *

Patterns/Rhombus.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Rhombus {
2+
public static void main(String[] args) {
3+
int i, j, k;
4+
int size = 10;
5+
char c = '*';
6+
7+
for(i=0; i<size; i++){
8+
for(j=0; j<i; j++)
9+
System.out.print(" ");
10+
for(k=0; k<size; k++){
11+
System.out.print(c+" ");
12+
}
13+
System.out.println();
14+
}
15+
}
16+
}

Patterns/RightHalfPyramid.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class RightHalfPyramid {
2+
public static void main(String[] args) {
3+
char c = '*';
4+
int limit = 10;
5+
6+
for (int i = 1; i <= limit; i++) {
7+
for (int j = 1; j <= i; j++) {
8+
System.out.print(c+" ");
9+
}
10+
System.out.println();
11+
}
12+
13+
}
14+
}
15+
16+
/* Expected output */
17+
// *
18+
// * *
19+
// * * *
20+
// * * * *
21+
// * * * * *

0 commit comments

Comments
 (0)