-1
はリターンというNumberFormatException
私はint
にString
を変換するInteger.parseInt()
を使用しようと、それが動作しない場合は、catch
いますクラッシュし、ユーザーを求めるプロンプトは表示します。Integer.parseInt()は、Javaプログラム
しかし、String
の値を入力すると、私を再割り当てする代わりに、プログラムがフリーズします。
keepLooping = true;
while(keepLooping) {
String unconvertedString = "";
int convertedInt = 0;
try {
System.out.print("Enter a string to be parsed into an integer: ");
unconvertedString = userInput.next();
convertedInt = Integer.parseInt(unconvertedString);
keepLooping = false;
}
catch (NumberFormatException e) {
userInput.next();
}
}
intを指定すると正しく動作しますか? userInputとは何ですか? – Reisclef
'next()'はどう思いますか? –
'userInput'とは何ですか? 'userInput.next()'は何をしますか? – YoungSpice