我有一個菜單驅動的程序,用戶被提示輸入可能的整數,因爲他們想要建立一個二叉搜索樹 - 我剛剛開始並且卡住了失控的閱讀他們的整數一旦他們打「Q」當從用戶輸入掃描整數時使用char哨兵
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」任何想法?
不錯,忘了那個。這也總是讓我感到... – 2012-08-01 22:07:55
啊啊是的 - 在鑽入C++後很難讓C++失去它的大腦! – 2012-08-01 22:11:51
告訴我關於它的事情:) – ryanbwork 2012-08-01 22:14:59