【发布时间】:2019-01-17 00:32:56
【问题描述】:
我正在尝试从数组中删除用户整数输入。但是,我无法获得输入的值。
while(keepGoing)
{
while (!scan.hasNextInt() )
{
scan.next();
System.out.print('\n'+"Choose a valid number: ");
}
int unitA = scan.nextInt();
if (unitA < 1)
{
System.out.print('\n'+"Choose one of the options: ");
keepGoing = true;
}
else if (unitA > 14)
{
System.out.print('\n'+"Choose one of the options: ");
keepGoing = true;
}
else
lengthValue.remove(unitA);
scan.close();
keepGoing = false;
}
//lengthValue.remove(int unitA);
System.out.println(unitA);
【问题讨论】:
-
好吧,
hasNextInt()和next()寻找完全不同的令牌。为什么要以这种方式测试流? -
我只是想避免输入字符串。我知道这是一种奇怪的方式,你有什么更好的方法吗?
-
我为您重新缩进了您的代码,使其与大括号匹配。仔细看看。
标签: java arrays if-statement while-loop java.util.scanner