teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

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

2020/08/31 14:05

投稿

cretter
cretter

スコア91

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 static void main(String[] args)
10
+ public class calcu01
10
11
  {
12
+ public static void main(String[] args)
13
+ {
14
+ Scanner sc = new Scanner(System.in);
11
- while(true){
15
+ while(true){
12
- System.out.print(">> ");
16
+ System.out.print(">> ");
13
- if (!sc.hasNextLine()) break;
17
+ if (!sc.hasNextLine()) break;
14
- String line = sc.nextLine();
18
+ String line = sc.nextLine();
15
- Scanner sc2 = new Scanner(line);
19
+ Scanner sc2 = new Scanner(line);
16
- try{
20
+ try{
17
- double x = sc2.nextDouble();
21
+ double x = sc2.nextDouble();
18
- String op = sc2.next();
22
+ String op = sc2.next();
19
- double y = sc2.nextDouble();
23
+ double y = sc2.nextDouble();
20
- double z = 0;
24
+ double z = 0;
21
- switch(op){
25
+ switch(op){
22
- case "q": z = x + y; break;
26
+ case "q": z = x + y; break;
23
- case "w": z = x - y; break;
27
+ case "w": z = x - y; break;
24
- case "e": z = x * y; break;
28
+ case "e": z = x * y; break;
25
- case "r": z = x / y; break;
29
+ case "r": z = x / y; break;
26
- case "z":
30
+ case "z":
27
- put("終了します");
31
+ put("終了します");
28
- System.exit(0);
32
+ System.exit(0);
29
- break;
33
+ break;
34
+ }
35
+ System.out.println(z);
30
36
  }
37
+ catch(Exception e){
31
- System.out.println(z);
38
+ System.out.println(" Error");
39
+ }
40
+ sc2.close();
32
41
  }
33
- catch(Exception e){
34
- System.out.println(" Error");
35
- }
36
- sc2.close();
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);