【发布时间】:2014-10-18 13:10:47
【问题描述】:
我想在while循环中使用单个扫描仪输入作为多个条件,可以检查输入是否正确,如果不正确则重新输入输入值。
类似这样的:
while(scannerInput is a int AND scannerInput is > than 0 AND scannerInput is < 10)
{
//CODE
}
但如果我使用scanner.hasNextInt() 和scanner.nextInt() 它会提示我输入而不是使用相同的输入
while (scaner.hasNextInt() && scaner.nextInt() > 0 && scaner.nextInt() < 10) {
}
有没有办法存储第一个输入并一次又一次地重复使用它,或者我的问题有更好的解决方案吗?
【问题讨论】:
-
是的,将它存储在一个变量中。
标签: java