回答編集履歴

1

出力フォーマット間違い

2022/07/02 17:34

投稿

jimbe
jimbe

スコア12648

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: %c %s\n", no, " +-*".charAt(c), line);
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: package teratail_java.q_6hgy0u9a4yg0a0;
27
+ 0001: package teratail_java.q_6hgy0u9a4yg0a0;
28
- 0002:
28
+ 0002:
29
- 0003: import java.io.*;
29
+ 0003: import java.io.*;
30
- 0004:
30
+ 0004:
31
- 0005: + public class AddLineNumber {
31
+ 0005:+ public class AddLineNumber {
32
- 0006: + public static void main(String[] args) {
32
+ 0006:+ public static void main(String[] args) {
33
- 0007: try(BufferedReader br = new BufferedReader(new FileReader("AddLineNumber.java"));
33
+ 0007: try(BufferedReader br = new BufferedReader(new FileReader("AddLineNumber.java"));
34
- 0008: + PrintWriter pw = new PrintWriter(new FileOutputStream("Output.txt"));) {
34
+ 0008:+ PrintWriter pw = new PrintWriter(new FileOutputStream("Output.txt"));) {
35
- 0009: String line;
35
+ 0009: String line;
36
- 0010: + for(int no=1; (line=br.readLine()) != null; no++) {
36
+ 0010:+ for(int no=1; (line=br.readLine()) != null; no++) {
37
- 0011: * int c = (line.contains("{") ? 1 : 0) + (line.contains("}") ? 2 : 0);
37
+ 0011:* int c = (line.contains("{") ? 1 : 0) + (line.contains("}") ? 2 : 0);
38
- 0012: pw.printf("%04d: %c %s\n", no, " +-*".charAt(c), line);
38
+ 0012: pw.printf("%04d:%c %s\n", no, " +-*".charAt(c), line);
39
- 0013: - }
39
+ 0013:- }
40
- 0014: * } catch(IOException e) {
40
+ 0014:* } catch(IOException e) {
41
- 0015: e.printStackTrace();
41
+ 0015: e.printStackTrace();
42
- 0016: - }
42
+ 0016:- }
43
- 0017: - }
43
+ 0017:- }
44
- 0018: - }
44
+ 0018:- }
45
45
  ```