回答編集履歴
1
printf を使うコードを追加
test
CHANGED
@@ -27,3 +27,37 @@
|
|
27
27
|
}
|
28
28
|
|
29
29
|
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
printf を使うと、
|
34
|
+
|
35
|
+
```Java
|
36
|
+
|
37
|
+
class Main {
|
38
|
+
|
39
|
+
public static void main(String args[]) {
|
40
|
+
|
41
|
+
int n = Integer.valueOf(args[0]);
|
42
|
+
|
43
|
+
String fmt1 = String.format("%%%dc%%n", n);
|
44
|
+
|
45
|
+
if (n > 0) System.out.printf(fmt1, '*');
|
46
|
+
|
47
|
+
for (int i = 2 - n; i < n - 1; i++) {
|
48
|
+
|
49
|
+
int m = Math.abs(i) + 1;
|
50
|
+
|
51
|
+
String fmt2 = String.format("%%%dc%%%dc%%n", m, (n - m) * 2);
|
52
|
+
|
53
|
+
System.out.printf(fmt2, '*', '*');
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
if (n > 1) System.out.printf(fmt1, '*');
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
```
|