-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava050_array.java
More file actions
45 lines (34 loc) · 805 Bytes
/
Java050_array.java
File metadata and controls
45 lines (34 loc) · 805 Bytes
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
package java0824_array;
/*
* 1 2 3 4 5
* 6 7 8 9 10
* 11 12 13 14 15
* 16 17 18 19 20
[출력결과]
1 2 * 4 5
* 7 8 * 10
11 * 13 14 *
16 17 * 19 20
*/
public class Java050_array {
public static void main(String[] args) {
int[][] num = new int[4][5];
int cnt = 1;
for (int row = 0; row < num.length; row++) {
for (int col = 0; col < num[row].length; col++) {
num[row][col] = cnt++;
}
}
///////////////////////////////////////////////////////////
for (int row = 0; row < num.length; row++) {
for (int col = 0; col < num[row].length; col++) {
if (num[row][col] % 3 == 0) {
System.out.printf("%4c", '*');
} else {
System.out.printf("%4d", num[row][col]);
}
}
System.out.println();
}
}
}