ユーザーが入力した値が typeintであり、 と の間liminfであるかどうかを確認するメソッドを作成しましたlimsup。値を返すので、メニュー オプションとして使用できます。文字列messageはユーザーに何かを入力するように指示し、 はユーザーにとerrorの間の数字を使用するように指示します。limunflimsup
私の問題は、たとえば、ユーザーが数字の 10 を入力し、それliminfが 7 とlimsupe 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;
}