Scanner in = new Scanner(System.in);
System.out.println("猜1到10的号码r");
String a = in.next();
int b = 0;
while(true){
try {
b = Integer.parseInt(a);
if(b<=10){
break;
}else{
System.out.println("猜1到10的号码");
a=in.next();
}
} catch (Exception e) {
System.out.println("猜1到10的号码r");
a=in.next();
}
}
int c=(int)(Math.random()*10);
while(true){
if(b==c){
c=(int)(Math.random()*10);
}else{
break;
}
}
System.out.println("对不起你的答案是错的,正确答案是:"+c);
in.close();
}
}
这段代码可以让抽奖的用户永远猜不到正确答案,因为我添加了一个整数,然后我想写一个办法,做一个计算,怎么利用return得出我作弊的号码?
酒木君
相关分类