java中输入类型不匹配异常,关于输入类型不匹配的异常处理,为什么我第一种代码会进入死循环?是input.next()的值没有变吗?...

76b1049c8193ad7d9759a63e69a2d117.png

风傲天

p.ID=input.nextInt();Scans the next token of the input as an int.An invocation of this method of the form  nextInt() behaves in exactly the same way as the invocation nextInt(radix), where radix is the default radix of this scanner.Returns:the int scanned from the inputThrows:InputMismatchException - if the next token does not match the Integer         regular expression, or is out of rangeNoSuchElementException -  if input is exhaustedIllegalStateException -  if this scanner is closed需要返回一个String类型,如果你的p.ID是一个int类型的确是不符合下面的正常代码是先输入的String类型的str.然后由p.ID = Integer.parseInt(str);int java.lang.Integer.parseInt(String s) throws NumberFormatExceptionParses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u005Cu002D') to indicate a negative value or an ASCII plus sign '+' ('\u005Cu002B') to indicate a positive value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseInt(java.lang.String, int) method.Parameters:s     a String containing the int             representation to be parsedReturns:the integer value represented by the argument in decimal.Throws:NumberFormatException -   if the string does not contain a               parsable integer.转换为int类型的p.ID

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值