package EEE;
import java.util.Random;
import java.util.Scanner;
public class CaiShuZi {
@SuppressWarnings("resource")
public static void main(String[] args) {
Random r = new Random();
Scanner sc = new Scanner(System.in);
int sj = r.nextInt(101);
int a=4;
while (a>=0) {
System.out.println("请输入你猜的数字:");
int sr = sc.nextInt();
if (sr==sj) {
System.out.println("你猜对了");
}else if (sr>sj) {
System.out.println("你猜大了还有"+(a--)+"次机会");
}else if(sr<sj){
System.out.println("你猜小了"+(a--)+"次机会");
}
}
}
}
|
|