ユーザー入力を取得し、-30 と 40 の範囲外の値を無視するように求められました。無効な数値をスキップするには、'continue' ステートメントを使用します。継続/中断は悪い習慣であると言っている情報源をグーグルで検索しました。IDE は、「不要な続行」の警告もスローしています。以下のコードは、この問題を解決するための適切な方法ですか?警告をオーバーライドするか、対処する必要がありますか?
私のコードは次のとおりです。
public class Temperatures
{
@SuppressWarnings("UnnecessaryContinue")
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
// Write your code here.
while(true)
{
//ask user for input
double userInput = Double.parseDouble(reader.nextLine());
//makes sure temperature is within range, if it isn't ignores value and moves on
if (userInput < -30.0 || userInput > 40.0)
{
continue;
}
//adds value to graph
else
{
Graph.addNumber(userInput);
}
}
}