二分探索木を構築するために、ユーザーが好きなだけ整数を入力するように求められるメニュー方式のプログラムがあります。開始したばかりで、「Q」に達すると整数の読み取りができなくなります。
switch(inputOption){
case 1:
System.out.println("You've selected to create a new binary tree." + "\n");
Scanner scan = new Scanner(System.in);
String again;
String tempInput;
Boolean repeat = true;
try{
System.out.println("Please enter as many integers as you'd like, hit 'Q' when you are finished." + "\n");
do{
tempInput = scan.next();
if(tempInput != "Q"){
integerInput = Integer.parseInt(tempInput);
repeat = true;
}
else
repeat = false;
}while(repeat);
}catch(InputMismatchException e){}
「Q」を認識させる方法について何かアイデアはありますか?