大家帮我看下程序,注释的地方有问题!谢谢您!

a241250 2007-10-24 09:17:40
import java.util.Random;
import java.util.Scanner;
public class test5 {


public static void main(String[] args) {

final int quit = -1;
int time = 1;
int a,b;
String q;
Random ran =new Random();
Scanner scan= new Scanner(System.in);
System.out.println ("是否进行游戏 Y/N");
q=scan.nextLine();
while(q.equalsIgnoreCase("y"))
{
b=ran.nextInt(100)+1;
System.out.println ("请输入一个1~100的整数,输入-1退出:");
a=scan.nextInt();

while(b!=a&&a!=quit)
{

time++;
if(b>a) System.out.println("smaller than real");
else System.out.println("bigger than real");
System.out.println ("请输入一个1~100的整数,输入-1退出:");
a = scan.nextInt();
}

if(a==quit) break;
else
System.out.println ("猜对了!!!"+"输入了"+time+"次");
System.out.println ("是否进行游戏 Y/N");
q=scan.nextLine(); //不读
System.out.println("********");
}
System.out.println("退出成功!");

}

}
...全文
97 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
a241250 2007-10-24
  • 打赏
  • 举报
回复
谢谢您 ! 我试试看!!
lanseliuying 2007-10-24
  • 打赏
  • 举报
回复
System.out.println ("是否进行游戏 Y/N");
q=scan.nextLine(); //不读
System.out.println("********");
再次读的时候要使用新的Scanner对象
改成这样:
System.out.println ("是否进行游戏 Y/N");
scan= new Scanner(System.in);
q=scan.nextLine();
System.out.println("********");

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧