懒得打字了,就直接复制粘贴
package Day03;
import java.util.Random;
import java.util.Scanner;
public class day0301 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("是否开始游戏"+"\n"+"Y表示是"+" "+"N表示否");
String a = scanner.next();
if(a.equals("Y")) {
boolean ss = true;
do{
System.out.println("猜数游戏开始");
Random random =new Random(); //产生随机数
int b = random.nextInt(10);
int c = scanner.nextInt(); //用户输入
do { //比较提醒
if(c>b) {
System.out.println("太大了");
int e = scanner.nextInt();
c = e;
}
else if(c<b) {
System.out.println("太小了");
int f = scanner.nextInt();
c = f;
}
}while(c!=b);
System.out.println("正确答案是"+c);
ss = false;
System.out.println("是否继续游戏"+"\n"+"Y"+" "+"N");
String gg = scanner.next();
if(gg.equals("Y")) {
ss = true;
}
else {
System.out.println("正在离开");
return;
}
}
while(ss);
}else {
System.out.println("正在离开");
return;
}
}
}
感谢我清华光头大哥,谢谢,谢谢,谢谢,谢谢我清华光头大哥