System.out.println("你所需的密码长度:");
String str = Keyboard.readInput();
int password= Integer.parseInt(str);
if(password<8 || password>24){
System.out.println(”输入错误重新输入");
continue;
} else {
return password;
}
IDE说continue不在loop里面
IDE 告诉我
Exception in thread "main" java.lang.NumberFormatException: Cannot parse null string
为什么不可以转换string呢?我的string是用户输入的数字,是不可以用Integer.parseInt么?
还有我的continue不可以在这里用是为什么呀?
谢谢大家的帮助!
(1)continue 是用在循环语句中的,比如 for,while
(2)str 数据是 空字符串,Integer.parseInt 不能转换空字符串。检查一下str,可以打印一下看看。
什么都不输入会当成空字符串的 肯定报错啊 可以用 lang3里的 NumberUtils.toInt() 如果输入空 返回0