forked from corock/java-practice02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProb05.java
More file actions
61 lines (44 loc) · 1 KB
/
Copy pathProb05.java
File metadata and controls
61 lines (44 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package practice02;
import java.util.Random;
import java.util.Scanner;
public class Prob05 {
public static void main(String[] args) {
Random r = new Random();
Scanner s = new Scanner(System.in);
int start;
int end;
int n;
int check;
int k;
boolean endGame;
while(true) {
start = 1;
end = 100;
n = 1;
k = r.nextInt(100) + 1;
endGame =true;
System.out.println("수를 결정하였습니다. 맞추어 보세요");
while (endGame) {
System.out.println(start + "-" + end);
System.out.print(n++ + ">>");
check = s.nextInt();
if (check == k) {
System.out.println("맞았습니다.");
endGame = false;
} else if (check > k) {
System.out.println("더 낮게");
end = check;
} else if (check < k) {
System.out.println("더 높게");
start = check;
}
}
System.out.print("다시하시겠습니까(y/n)>>");
String answer = s.next();
if(answer.equals("y")) {
}else if(answer.equals("n")) {
break;
}
}
}
}