質問編集履歴

3

エラー処理

2020/06/11 04:17

投稿

yufu8
yufu8

スコア5

test CHANGED
File without changes
test CHANGED
@@ -26,13 +26,13 @@
26
26
 
27
27
  String message = "";
28
28
 
29
- String memo = "";
30
29
 
31
30
 
31
+ FileWriter filewriter = new FileWriter(file);
32
32
 
33
33
  if (file.exists()) {
34
34
 
35
- System.out.println("上書きする : ok");
35
+ System.out.println("上書き : ok");
36
36
 
37
37
  System.out.println("終了 : その他");
38
38
 
@@ -40,19 +40,31 @@
40
40
 
41
41
  System.out.println();
42
42
 
43
- if (passKey.equalsIgnoreCase("ok")) {
43
+ if (passKey.equalsIgnoreCase("w")) {
44
44
 
45
- while (message != "finish") {
45
+ try {
46
46
 
47
- FileWriter filewriter = new FileWriter(file);
47
+ while (!(message.equals("finish"))) {
48
48
 
49
- message = new java.util.Scanner(System.in).nextLine();
49
+ System.out.print("Input String ");
50
50
 
51
- filewriter.write(message);
51
+ message += new java.util.Scanner(System.in).nextLine();
52
52
 
53
-
53
+ filewriter.write(message);
54
54
 
55
+
56
+
57
+ }
58
+
55
- }filewriter.close();
59
+ filewriter.close();
60
+
61
+ } catch (IOException e) {
62
+
63
+ System.out.println(e);
64
+
65
+
66
+
67
+ }
56
68
 
57
69
  } else {
58
70
 
@@ -68,19 +80,19 @@
68
80
 
69
81
  try {
70
82
 
83
+ while (!(message.equals("finish"))) {
84
+
85
+ message = new java.util.Scanner(System.in).nextLine();
86
+
87
+ System.out.print("Input String");
88
+
71
- FileWriter filewriter = new FileWriter(file);
89
+ filewriter.write(message);
72
90
 
73
91
 
74
92
 
75
- while (memo != "finish") {
93
+ }
76
94
 
77
- memo = new java.util.Scanner(System.in).nextLine();
78
-
79
- filewriter.write(memo);
80
-
81
-
82
-
83
- }filewriter.close();
95
+ filewriter.close();
84
96
 
85
97
  } catch (IOException e) {
86
98
 
@@ -98,6 +110,4 @@
98
110
 
99
111
  }
100
112
 
101
-
102
-
103
113
  ```

2

文法の変更

2020/06/11 04:17

投稿

yufu8
yufu8

スコア5

test CHANGED
File without changes
test CHANGED
@@ -50,9 +50,9 @@
50
50
 
51
51
  filewriter.write(message);
52
52
 
53
- filewriter.close();
53
+
54
54
 
55
- }
55
+ }filewriter.close();
56
56
 
57
57
  } else {
58
58
 
@@ -78,9 +78,9 @@
78
78
 
79
79
  filewriter.write(memo);
80
80
 
81
- filewriter.close();
81
+
82
82
 
83
- }
83
+ }filewriter.close();
84
84
 
85
85
  } catch (IOException e) {
86
86
 

1

whileの条件変更

2020/06/11 00:08

投稿

yufu8
yufu8

スコア5

test CHANGED
File without changes
test CHANGED
@@ -40,9 +40,9 @@
40
40
 
41
41
  System.out.println();
42
42
 
43
- if (passKey.equals("ok")) {
43
+ if (passKey.equalsIgnoreCase("ok")) {
44
44
 
45
- while (message.equals("finish")) {
45
+ while (message != "finish") {
46
46
 
47
47
  FileWriter filewriter = new FileWriter(file);
48
48
 
@@ -72,7 +72,7 @@
72
72
 
73
73
 
74
74
 
75
- while (memo.equals("finish")) {
75
+ while (memo != "finish") {
76
76
 
77
77
  memo = new java.util.Scanner(System.in).nextLine();
78
78