java报错出现未知源_在java.util.Scanner.throwFor(未知源)错误

private static int posNum() {

Scanner scan = new Scanner(System.in);

int input = 0;

boolean error;

if (scan.hasNextInt()) {

input = scan.nextInt();

error = input <= 0;

} else {

28 scan.next();

error = true;

}

while (error) {

System.out.print("Invalid input. Please reenter: ");

if (scan.hasNextInt()) {

input = scan.nextInt();

error = input <= 0;

} else {

scan.next();

error = true;

}

}

scan.close();

return input;

}

因此,第二次调用此方法将返回以下错误。

Exception in thread "main" java.util.NoSuchElementException

at java.util.Scanner.throwFor(Unknown Source)

at java.util.Scanner.next(Unknown Source)

at q2.CylinderStats.posNum(CylinderStats.java:28)

at q2.CylinderStats.main(CylinderStats.java:62)

第一个调用rad = posNum();运行良好,然后第二个调用运行,height = posNum();不允许在错误发生之前输入值。

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值