回答編集履歴
1
ソースの変更
test
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
```Java
|
6
|
+
|
7
|
+
import java.util.*;
|
8
|
+
|
9
|
+
|
6
10
|
|
7
11
|
public class Main {
|
8
12
|
|
@@ -14,57 +18,23 @@
|
|
14
18
|
|
15
19
|
System.out.println("加法 -> 1 減法 -> 2 を入力");
|
16
20
|
|
17
|
-
int n;
|
21
|
+
int n = Integer.parseInt(sc.nextLine());
|
18
22
|
|
19
|
-
|
23
|
+
|
20
24
|
|
21
|
-
|
25
|
+
int num1, num2;
|
22
26
|
|
23
|
-
|
27
|
+
System.out.println("2つの数字を入力");
|
24
28
|
|
25
|
-
|
29
|
+
num1 = Integer.parseInt(sc.nextLine());
|
26
30
|
|
27
|
-
}
|
28
|
-
|
29
|
-
|
31
|
+
num2 = Integer.parseInt(sc.nextLine());
|
30
32
|
|
31
33
|
|
32
34
|
|
33
|
-
|
35
|
+
Calculation calc = new Calculation(num1,num2);
|
34
36
|
|
35
|
-
System.out.println("2つの数字を入力");
|
36
|
-
|
37
|
-
num1 = Integer.parseInt(sc.nextLine());
|
38
|
-
|
39
|
-
num2 = Integer.parseInt(sc.nextLine());
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
Calculation calc = new Calculation();
|
44
|
-
|
45
|
-
Calculation value = calc.calcMethod(num1, num2);
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
switch(n){
|
50
|
-
|
51
|
-
case 1:
|
52
|
-
|
53
|
-
|
37
|
+
calc.print_answer(n);
|
54
|
-
|
55
|
-
break;
|
56
|
-
|
57
|
-
case 2:
|
58
|
-
|
59
|
-
System.out.println(value.subtraction);
|
60
|
-
|
61
|
-
break;
|
62
|
-
|
63
|
-
default:
|
64
|
-
|
65
|
-
break;
|
66
|
-
|
67
|
-
}
|
68
38
|
|
69
39
|
System.out.println();
|
70
40
|
|
@@ -76,21 +46,33 @@
|
|
76
46
|
|
77
47
|
class Calculation{
|
78
48
|
|
79
|
-
int
|
49
|
+
private int MyNum1;
|
80
50
|
|
81
|
-
int
|
51
|
+
private int MyNum2;
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
public Calculation(int num1,int num2){
|
56
|
+
|
57
|
+
MyNum1 = num1;
|
58
|
+
|
59
|
+
MyNum2 = num2;
|
60
|
+
|
61
|
+
}
|
82
62
|
|
83
63
|
|
84
64
|
|
85
|
-
public
|
65
|
+
public void print_answer(int n){
|
86
66
|
|
87
|
-
|
67
|
+
n = n % 2;
|
88
68
|
|
89
|
-
|
69
|
+
if(n == 0){
|
90
70
|
|
91
|
-
|
71
|
+
MyNum2 *= -1;
|
92
72
|
|
73
|
+
}
|
74
|
+
|
93
|
-
|
75
|
+
System.out.println(MyNum1 + MyNum2);
|
94
76
|
|
95
77
|
}
|
96
78
|
|