ユーザーが入力した値が typeint
であり、 と の間liminf
であるかどうかを確認するメソッドを作成しましたlimsup
。値を返すので、メニュー オプションとして使用できます。文字列message
はユーザーに何かを入力するように指示し、 はユーザーにとerror
の間の数字を使用するように指示します。limunf
limsup
私の問題は、たとえば、ユーザーが数字の 10 を入力し、それliminf
が 7 とlimsup
e 9 の場合、数字の 10 が と の間にあったように実行されることlimsup
ですliminf
。
public static int readInput(String message, String error, int liminf, int limsup, Scanner rd){
int option = 0;
do {
option = rd.nextInt();
System.out.println(message);
while (!rd.hasNextInt()) {
System.out.println("Please enter the option");
rd.nextLine();
}
option = rd.nextInt();
canal.nextLine();
} while (option > limsup || option < liminf);
return option;
}