forked from Krushna-Prasad-Sahoo/JavaCode-Hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pattern.java
139 lines (114 loc) · 3.48 KB
/
pattern.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.company;
public class pattern {
public static void main(String[] args) {
int n=3;
pattern31(2);
System.out.println();
pattern1(n);
System.out.println();
pattern2(4);
System.out.println();
pattern3(3);
System.out.println();
pattern4(4);
System.out.println();
pattern5(3);
System.out.println();
pattern30(n);
System.out.println();
pattern6(5);
System.out.println();
pattern17(3);
System.out.println();
}
static void pattern2(int n){
for (int row = 1; row <=n; row++) {
// for every row, run the column
for (int col = 1; col <=n ; col++) {
System.out.print("* ");
}
System.out.println();
}
}
static void pattern1(int n){
for (int row = 1; row <=n; row++) {
// for every row, run the column
for (int col = 1; col <=row ; col++) {
System.out.print("* ");
}
System.out.println();
}
}
static void pattern3(int n){
for (int row = 1; row <= n; row++) {
// for every row, run the column
for (int col = n; col >=row ; col--) {
System.out.print("* ");
}
System.out.println();
}
}
static void pattern4(int n){
for (int row = 1; row <=n ; row++) {
for (int col = 1; col <=row ; col++) {
System.out.print(col+" ");
}
System.out.println();
}
}static void pattern5(int n){
for (int row = 1; row <=2*n-1 ; row++) {
int col= row>n ? 2*n-row : row;
for (int colum=0; colum <col; colum++) {
System.out.print(" *");
}
System.out.println();
}
}
static void pattern6(int n){
for (int row = 1; row <=2*n-1 ; row++) {
int col= row>n ? 2*n-row : row;
int space=n-col;
for (int i = 0; i < space; i++) {
System.out.print(" ");
}
for (int colum=0; colum <col; colum++) {
System.out.print(" *");
}
System.out.println();
}
}
static void pattern30(int n){
for(int row=1;row<=n;row++){
int space = n-row;
for (int i = 1; i <=space; i++) {
System.out.print(" ");
}
for (int col = row; col >=1 ; col--) {
System.out.print(col+" ");
}
for (int column = 2; column <=row ; column++) {
System.out.print(column+" ");
}
System.out.println();
}
}
static void pattern17(int n){
n=2*n;
for(int row=1;row<=n;row++){
for (int col = 0; col<=n ; col++) {
System.out.print(col+" ");
}
System.out.println();
}
}
static void pattern31(int n){
n=2*n;
for (int row = 0; row <=n ; row++) {
for (int col = 0; col <=n ; col++) {
int atEveryIndex = Math.min(Math.min(row,col),Math.min(n-row,n-col));
System.out.print(atEveryIndex+" ");
}
System.out.println();
}
}
}