質問編集履歴

2

マークダウンに記述

2020/03/25 01:54

投稿

hiro.a
hiro.a

スコア28

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
- ``````java
1
+ ``````
2
2
 
3
- ここに言語を入力
3
+ java
4
4
 
5
5
  ```
6
6
 

1

コードをマークダウンに記述

2020/03/25 01:54

投稿

hiro.a
hiro.a

スコア28

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,12 @@
1
+ ``````java
2
+
3
+ ここに言語を入力
4
+
5
+ ```
6
+
7
+ コード
8
+
1
- equalsを簡単なゲームを作成しています。
9
+ ```equalsを簡単なゲームを作成しています。
2
10
 
3
11
 
4
12
 
@@ -14,124 +22,116 @@
14
22
 
15
23
 
16
24
 
17
-
18
-
19
- public static void main(String[] args) {
25
+ public static void main(String[] args) {
20
-
21
-
22
-
23
- Scanner sc = new Scanner(System.in);
24
-
25
- System.out.println("**********");
26
-
27
- System.out.println("*High & Low*");
28
-
29
- System.out.println("**********");
30
-
31
-
32
-
33
- System.out.println();
34
-
35
-
36
-
37
- int leftCard = (int)(Math.random()*9)+1;
38
-
39
- System.out.println(" [問題表示] ");
40
-
41
- System.out.println("***** *****");
42
-
43
- System.out.println("* * * * *");
44
-
45
- System.out.println("* " +leftCard + " * * * *");
46
-
47
- System.out.println("* * * * *");
48
-
49
- System.out.println("***** *****");
50
-
51
- System.out.println("High or Low ?(h/l) > ");
52
-
53
- String select = sc.nextLine();
54
-
55
-
56
-
57
- if (select.equals("h")) {
58
-
59
- System.out.println("→Highを選択しました。");
60
-
61
-
62
-
63
- } else {
64
-
65
- System.out.println("→Lowを選択しました。");
66
-
67
- };
68
-
69
-
70
-
71
- System.out.println("");
72
-
73
-
74
-
75
- System.out.println("[結果表示]");
76
-
77
- System.out.println("***** *****");
78
-
79
- System.out.println("* * * *");
80
-
81
- int rightCard = (int)(Math.random()*9)+1;
82
-
83
- System.out.println("* +leftCard+ * * +rightCard+ *");
84
-
85
- System.out.println("* * * *");
86
-
87
- System.out.println("***** *****");
88
-
89
-
90
-
91
-
92
-
93
- String result ;
94
-
95
- if (leftCard < rightCard) {
96
-
97
- result = "h" ;
98
-
99
- } else if (leftCard >rightCard ) {
100
-
101
- result = "l";
102
-
103
- } else if ( leftCard == rightCard) {
104
-
105
- result = select ;
106
-
107
- };
108
-
109
-
110
-
111
- if (result.equals(select)) {
112
-
113
- System.out.println("→You Win!");
114
-
115
- } else if (result != select) {
116
-
117
- System.out.println("→you Lose...");
118
-
119
- };
120
-
121
-
122
-
123
-
124
-
125
- System.out.println("");
126
-
127
-
128
-
129
- System.out.println("--ゲーム終了--");
130
26
 
131
27
 
132
28
 
29
+ Scanner sc = new Scanner(System.in);
30
+
31
+ System.out.println("******");
32
+
33
+ System.out.println("*High & Low*");
34
+
35
+ System.out.println("******");
133
36
 
134
37
 
135
- }
136
38
 
39
+ System.out.println();
40
+
41
+
42
+
43
+ int leftCard = (int)(Math.random()*9)+1;
44
+
45
+ System.out.println(" [問題表示] ");
46
+
47
+ System.out.println("* *");
48
+
49
+ System.out.println("* * * * *");
50
+
51
+ System.out.println("* " +leftCard + " * * * *");
52
+
53
+ System.out.println("* * * * *");
54
+
55
+ System.out.println("* *");
56
+
57
+ System.out.println("High or Low ?(h/l) > ");
58
+
59
+ String select = sc.nextLine();
60
+
61
+
62
+
63
+ if (select.equals("h")) {
64
+
65
+ System.out.println("→Highを選択しました。");
66
+
67
+
68
+
69
+ } else {
70
+
71
+ System.out.println("→Lowを選択しました。");
72
+
73
+ };
74
+
75
+
76
+
77
+ System.out.println("");
78
+
79
+
80
+
81
+ System.out.println("[結果表示]");
82
+
83
+ System.out.println("* *");
84
+
85
+ System.out.println("* * * *");
86
+
87
+ int rightCard = (int)(Math.random()*9)+1;
88
+
89
+ System.out.println("* +leftCard+ * * +rightCard+ *");
90
+
91
+ System.out.println("* * * *");
92
+
93
+ System.out.println("* *");
94
+
95
+
96
+
97
+ String result ;
98
+
99
+ if (leftCard < rightCard) {
100
+
101
+ result = "h" ;
102
+
103
+ } else if (leftCard >rightCard ) {
104
+
105
+ result = "l";
106
+
107
+ } else if ( leftCard == rightCard) {
108
+
109
+ result = select ;
110
+
111
+ };
112
+
113
+
114
+
115
+ if (result.equals(select)) {
116
+
117
+ System.out.println("→You Win!");
118
+
119
+ } else if (result != select) {
120
+
121
+ System.out.println("→you Lose...");
122
+
123
+ };
124
+
125
+
126
+
127
+ System.out.println("");
128
+
129
+
130
+
131
+ System.out.println("--ゲーム終了--");
132
+
133
+
134
+
137
- }
135
+ }
136
+
137
+ }