package com.alibaba.demo05;
import java.util.Random;
import java.util.Scanner;
public class lianxi4 {
public static void main(String[] args) {
Random ran = new Random();
System.out.println("请给出你的答案");
Scanner sc = new Scanner(System.in);
int a = ran.nextInt(50)+1;
System.out.println(a);
boolean boo = true;
for(int i = 1;i<=10;i++){
int x = sc.nextInt();
if(x==a){
System.out.println("猜对了,真棒");
boo = false;
}else {
if(i==5){
System.out.println("真笨,你没机会了");
boo = false;
}else {
if(x>a){
System.out.println("猜大了,你还有"+(5-i)+"次机会");
System.out.println("请再次给出你的答案");
}else {
System.out.println("猜小了,你还有"+(5-i)+"次机会");
System.out.println("请再次给出你的答案");
}
}
}
if(boo==false){
break;
}
}
}
}
02-10
3849
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)