import java.util.Random;
import java.util.Scanner;
class GussMath
{
public static void main(String[]agrs)
{
Scanner sc=new Scanner(System.in);
Random r=new Random();
boolean flag=true;
int b=(int)(r.nextInt(100));
while(flag)
{
int number=sc.nextInt();
if(number<1 || number>100)
{
System.out.println("请输入1~100之间的数");
// flag=false;
break;
}
if(number==b)
{
System.out.println("恭喜你,猜对了");
System.out.println("请问你还想继续玩吗?是请按Y/否请按N");
String s=sc.nextLine();
String c1="Y";
String c2="N";
if(sc.equals(c1))
{
Random ra=new Random();
//int b=(int)(ra.nextInt(100));//请各位大侠帮忙解决一下这里如何实现继续向下执行?(对循环中嵌套在返回去执行老是迷糊)
flag=true;
continue;
}
if(sc.equals(c2))
{
break;
}
//flag=false;
}
if(number>b)
{
System.out.println("大了,请继续");
continue;
}
if(number<b)
{
System.out.println("小了,请继续");
continue;
}
}
}
}
求大侠们给解决一下注释的地方!!! |
|