質問編集履歴

1

抜けていた部分を加えました。

2020/08/31 14:05

投稿

cretter
cretter

スコア91

test CHANGED
File without changes
test CHANGED
@@ -14,65 +14,73 @@
14
14
 
15
15
  ```java
16
16
 
17
+ import java.util.Scanner;
18
+
17
- public static void main(String[] args)
19
+ public class calcu01
18
20
 
19
21
  {
20
22
 
21
- while(true){
23
+ public static void main(String[] args)
22
24
 
23
- System.out.print(">> ");
25
+ {
24
26
 
25
- if (!sc.hasNextLine()) break;
27
+ Scanner sc = new Scanner(System.in);
26
28
 
27
- String line = sc.nextLine();
29
+ while(true){
28
30
 
29
- Scanner sc2 = new Scanner(line);
31
+ System.out.print(">> ");
30
32
 
31
- try{
33
+ if (!sc.hasNextLine()) break;
32
34
 
33
- double x = sc2.nextDouble();
35
+ String line = sc.nextLine();
34
36
 
35
- String op = sc2.next();
37
+ Scanner sc2 = new Scanner(line);
36
38
 
37
- double y = sc2.nextDouble();
39
+ try{
38
40
 
39
- double z = 0;
41
+ double x = sc2.nextDouble();
40
42
 
41
- switch(op){
43
+ String op = sc2.next();
42
44
 
43
- case "q": z = x + y; break;
45
+ double y = sc2.nextDouble();
44
46
 
45
- case "w": z = x - y; break;
47
+ double z = 0;
46
48
 
47
- case "e": z = x * y; break;
49
+ switch(op){
48
50
 
49
- case "r": z = x / y; break;
51
+ case "q": z = x + y; break;
50
52
 
51
- case "z":
53
+ case "w": z = x - y; break;
52
54
 
53
- put("終了します");
55
+ case "e": z = x * y; break;
54
56
 
55
- System.exit(0);
57
+ case "r": z = x / y; break;
56
58
 
59
+ case "z":
60
+
61
+ put("終了します");
62
+
63
+ System.exit(0);
64
+
57
- break;
65
+ break;
66
+
67
+ }
68
+
69
+ System.out.println(z);
58
70
 
59
71
  }
60
72
 
73
+ catch(Exception e){
74
+
61
- System.out.println(z);
75
+ System.out.println(" Error");
76
+
77
+ }
78
+
79
+ sc2.close();
62
80
 
63
81
  }
64
82
 
65
- catch(Exception e){
66
-
67
- System.out.println(" Error");
68
-
69
- }
70
-
71
- sc2.close();
72
-
73
- }
74
-
75
- sc.close();
83
+ sc.close();
76
84
 
77
85
  }
78
86