3 回答
![?](http://img1.sycdn.imooc.com/54584ee0000179f302200220-100-100.jpg)
TA贡献1906条经验 获得超10个赞
你可以做这样的事情。
// code
Scanner Invoermax = new Scanner(System.in);
System.out.println("Under which number you want to guess");
int Invoer = Invoermax.nextInt();
Invoermax.nextLine(); // reading empty space left
int Hoogte = ThreadLocalRandom.current().nextInt(1,Invoermax.nextInt());
// code
![?](http://img1.sycdn.imooc.com/533e4d5b0001d57502200203-100-100.jpg)
TA贡献1757条经验 获得超7个赞
您有两个Scanner.nextInt()调用,因此有两个输入读数,两个输入等待。
int Invoer = Invoermax.nextInt(); // the first input reading
int Hoogte = ThreadLocalRandom.current().nextInt(1,
Invoermax.nextInt()); // the second input reading
当您在控制台(任何类型)中输入两个 int 值时,您将看到结束打印行。
如果您的设计只有一个输入,则使用兑现值进行第二次使用
int Invoer = Invoermax.nextInt(); // the first input reading
int Hoogte = ThreadLocalRandom.current().nextInt(1,
Invoer ); // use cashed value
![?](http://img1.sycdn.imooc.com/533e4c5600017c5b02010200-100-100.jpg)
TA贡献1719条经验 获得超6个赞
每次您调用时,Scanner.nextInt()
它都会等待您的输入。
问题是你调用它两次,替换:
int Hoogte = ThreadLocalRandom.current().nextInt(1,Invoermax.nextInt());
使用您已经获得的变量:
int Hoogte = ThreadLocalRandom.current().nextInt(1,Invoer);
顺便说一句,通常在 java 中,字段/变量名称以小写字母开头,所以应该是hoogte
,等。inoverMax
inover
添加回答
举报