0

私はもともと、try catch なしで throw ステートメントを機能させようとしましたが、userInput = input.nextInt();行は正常に機能しました。しかし、try..catch を追加しようとすると、解決できないという私の入力が気に入らなかったのです。私のtry..catchはまだ正しいとは思いませんが、この入力が認識されるようになった後、それに取り組むことを計画していますが、それで見られるものについてのフィードバックもいただければ幸いです。

ありがとう

import java.util.Scanner;

    public class Program6 
    {
        public static void main(String[] args) 
        {
            final int NUMBER_HIGH_LIMIT = 100;
            final int NUMBER_LOW_LIMIT = 10;
            int userInput;

            try
            {
                System.out.print("Enter a number between 10 and 100: ");
                userInput = input.nextInt();//Says input cannot be resolved

                Verify v = new Verify(NUMBER_HIGH_LIMIT, NUMBER_LOW_LIMIT);
            }
            catch(NumberHighException exception)
            {
                userInput = 0;
            }
            catch(NumberLowException exception) 
            {
                userInput = 0;  
            }
        }
    }
4

1 に答える 1

4

と呼ばれるスキャナーを作成する必要がありますinput

public class Program6 {

  public static void main(String[] args) {
    final int NUMBER_HIGH_LIMIT = 100;
    final int NUMBER_LOW_LIMIT = 10;
    int userInput;

    try {
      Scanner input = new Scanner(System.in);
      System.out.print("Enter a number between 10 and 100: ");
      userInput = input.nextInt();//Says input cannot be resolved

      Verify v = new Verify(NUMBER_HIGH_LIMIT, NUMBER_LOW_LIMIT);

    } catch (NumberHighException exception) {
      userInput = 0;
    } catch (NumberLowException exception) {
      userInput = 0;
    }
  }
}
于 2013-10-17T21:50:29.747 に答える