回答編集履歴
1
出力フォーマット間違い
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
String line;
|
15
15
|
for(int no=1; (line=br.readLine()) != null; no++) {
|
16
16
|
int c = (line.contains("{") ? 1 : 0) + (line.contains("}") ? 2 : 0);
|
17
|
-
pw.printf("%04d:
|
17
|
+
pw.printf("%04d:%c %s\n", no, " +-*".charAt(c), line);
|
18
18
|
}
|
19
19
|
} catch(IOException e) {
|
20
20
|
e.printStackTrace();
|
@@ -24,22 +24,22 @@
|
|
24
24
|
```
|
25
25
|
実行結果(Output.txt)
|
26
26
|
```plain
|
27
|
-
0001:
|
27
|
+
0001: package teratail_java.q_6hgy0u9a4yg0a0;
|
28
|
-
0002:
|
28
|
+
0002:
|
29
|
-
0003:
|
29
|
+
0003: import java.io.*;
|
30
|
-
0004:
|
30
|
+
0004:
|
31
|
-
0005:
|
31
|
+
0005:+ public class AddLineNumber {
|
32
|
-
0006:
|
32
|
+
0006:+ public static void main(String[] args) {
|
33
|
-
0007:
|
33
|
+
0007: try(BufferedReader br = new BufferedReader(new FileReader("AddLineNumber.java"));
|
34
|
-
0008:
|
34
|
+
0008:+ PrintWriter pw = new PrintWriter(new FileOutputStream("Output.txt"));) {
|
35
|
-
0009:
|
35
|
+
0009: String line;
|
36
|
-
0010:
|
36
|
+
0010:+ for(int no=1; (line=br.readLine()) != null; no++) {
|
37
|
-
0011:
|
37
|
+
0011:* int c = (line.contains("{") ? 1 : 0) + (line.contains("}") ? 2 : 0);
|
38
|
-
0012:
|
38
|
+
0012: pw.printf("%04d:%c %s\n", no, " +-*".charAt(c), line);
|
39
|
-
0013:
|
39
|
+
0013:- }
|
40
|
-
0014:
|
40
|
+
0014:* } catch(IOException e) {
|
41
|
-
0015:
|
41
|
+
0015: e.printStackTrace();
|
42
|
-
0016:
|
42
|
+
0016:- }
|
43
|
-
0017:
|
43
|
+
0017:- }
|
44
|
-
0018:
|
44
|
+
0018:- }
|
45
45
|
```
|