質問編集履歴
1
抜けていた部分を加えました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,37 +6,41 @@
|
|
6
6
|
### 該当のソースコード
|
7
7
|
|
8
8
|
```java
|
9
|
+
import java.util.Scanner;
|
9
|
-
public
|
10
|
+
public class calcu01
|
10
11
|
{
|
12
|
+
public static void main(String[] args)
|
13
|
+
{
|
14
|
+
Scanner sc = new Scanner(System.in);
|
11
|
-
|
15
|
+
while(true){
|
12
|
-
|
16
|
+
System.out.print(">> ");
|
13
|
-
|
17
|
+
if (!sc.hasNextLine()) break;
|
14
|
-
|
18
|
+
String line = sc.nextLine();
|
15
|
-
|
19
|
+
Scanner sc2 = new Scanner(line);
|
16
|
-
|
20
|
+
try{
|
17
|
-
|
21
|
+
double x = sc2.nextDouble();
|
18
|
-
|
22
|
+
String op = sc2.next();
|
19
|
-
|
23
|
+
double y = sc2.nextDouble();
|
20
|
-
|
24
|
+
double z = 0;
|
21
|
-
|
25
|
+
switch(op){
|
22
|
-
|
26
|
+
case "q": z = x + y; break;
|
23
|
-
|
27
|
+
case "w": z = x - y; break;
|
24
|
-
|
28
|
+
case "e": z = x * y; break;
|
25
|
-
|
29
|
+
case "r": z = x / y; break;
|
26
|
-
|
30
|
+
case "z":
|
27
|
-
|
31
|
+
put("終了します");
|
28
|
-
|
32
|
+
System.exit(0);
|
29
|
-
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
System.out.println(z);
|
30
36
|
}
|
37
|
+
catch(Exception e){
|
31
|
-
|
38
|
+
System.out.println(" Error");
|
39
|
+
}
|
40
|
+
sc2.close();
|
32
41
|
}
|
33
|
-
catch(Exception e){
|
34
|
-
System.out.println(" Error");
|
35
|
-
}
|
36
|
-
|
42
|
+
sc.close();
|
37
43
|
}
|
38
|
-
sc.close();
|
39
|
-
}
|
40
44
|
public static void put(String str)
|
41
45
|
{
|
42
46
|
System.out.println(str);
|