質問編集履歴

2

タグの変更

2020/05/07 03:51

投稿

ODAICHI23
ODAICHI23

スコア0

test CHANGED
File without changes
test CHANGED
File without changes

1

ソースコードを追加しました。×Javascript〇Java

2020/05/07 03:51

投稿

ODAICHI23
ODAICHI23

スコア0

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,115 @@
16
16
 
17
17
  ### 該当のソースコード
18
18
 
19
+ import java.util.Scanner;
19
20
 
21
+
22
+
23
+ public class Janken {
24
+
25
+ public static void main(String[] args) {
26
+
27
+ System.out.println("---------------------------------------------------------------------");
28
+
29
+ System.out.println(" 計算脳トレ");
30
+
31
+ System.out.println("---------------------------------------------------------------------");
32
+
33
+ System.out.println();
34
+
35
+ System.out.println("==ルール説明==");
36
+
37
+ System.out.println("足す引く掛ける割るを使って0にしよう");
38
+
39
+ System.out.println();
40
+
41
+ System.out.println("---------------------------------------------------------------------");
42
+
43
+ System.out.println( "ゲーム開始");
44
+
45
+ System.out.println("---------------------------------------------------------------------");
46
+
47
+
48
+
49
+ Scanner scanner = new Scanner(System.in);
50
+
51
+ //親の数字を出す
52
+
53
+ int ranNum = new java.util.Random().nextInt(50)+51;
54
+
55
+ System.out.println("最初の数字は" + ranNum + "です。");
56
+
57
+
58
+
59
+ int keisan;
60
+
61
+
62
+
63
+ while(ranNum != 0 ) {
64
+
65
+ //計算用の数字を出す
66
+
67
+ int subNum = new java.util.Random().nextInt(9)+1;
68
+
69
+ System.out.println("今回の計算に使う数字は" + subNum + "です");
70
+
71
+ System.out.println("計算に使う文字を入力してください" + ranNum + "0:+ 1:- 2:* 3:/" + subNum);
72
+
73
+ keisan = Integer.parseInt(scanner.nextLine());
74
+
75
+
76
+
77
+ switch(keisan) {
78
+
79
+ case 0:
80
+
81
+ ranNum = ranNum + subNum;
82
+
83
+ System.out.println(ranNum);
84
+
85
+ break;
86
+
87
+ case 1:
88
+
89
+ ranNum = ranNum - subNum;
90
+
91
+ System.out.println(ranNum);
92
+
93
+ break;
94
+
95
+ case 2:
96
+
97
+ ranNum = ranNum * subNum;
98
+
99
+ System.out.println(ranNum);
100
+
101
+ break;
102
+
103
+ case 3:
104
+
105
+ ranNum = ranNum / subNum;
106
+
107
+ System.out.println(ranNum);
108
+
109
+ break;
110
+
111
+ default:
112
+
113
+ System.out.println("選択肢に無いものが選ばれました");
114
+
115
+ break;
116
+
117
+ }
118
+
119
+ System.out.println("計算結果は" + ranNum + "です。");
120
+
121
+ }
122
+
123
+
124
+
125
+ }
126
+
127
+ }
20
128
 
21
129
 
22
130