-
Notifications
You must be signed in to change notification settings - Fork 0
/
work1.java
55 lines (51 loc) · 1.32 KB
/
work1.java
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
package hellojava;
import java.util.Random;//导入随机数包
import java.util.Scanner;//导入键盘输入包
public class work1 {
public static void main(String[] args) {
System.out.println("这是猜数游戏,你有10次机会!");
System.out.println("请输入一个数字(0~50)");
Random game = new Random();
Scanner idea=new Scanner(System.in);
int number = game.nextInt(51);//随机产生一个小于51的整数
int times=1;
do {
System.out.println("你还有"+(11-times)+"次机会");
int num=idea.nextInt();
if(num==number)
{
System.out.println("正确");
break;
}
else if(num>number)
{
System.out.println("太大了");
}
else if(num<number)
{
System.out.println("太小了");
}
times++;
}while(times<=10);
if(times<=3)
{
System.out.println("棒极了");
}
else if(times<=5)
{
System.out.println("还不错");
}
else if(times<=8)
{
System.out.println("一般般");
}
else if(times<=10)
{
System.out.println("差");
}
else if(times==11)
{
System.out.println("失败");
}
}
}