有誰知道爲什麼我的掃描儀每三行要求輸入一次,而不是每一行?如果你運行它,你會看到它首先提出這個問題,但是不會再出現兩行,然後再次提出這個問題。我怎樣才能讓它在每一行都提問,更別說將它存儲在鏈表中。爲什麼我的掃描儀每三行詢問一次輸入?
import java.util.Scanner;
public class StackCalc {
public static StackLL stackll = new StackLL();
public static void create() {
String hold = new String();
Scanner scanner = new Scanner(System.in);
boolean running = true;
while (true) {
System.out.print("Enter number, math operation(+,-,*, or /), or Q to quit: ");
hold = scanner.next();
if (scanner.next().equals("Q") || scanner.next().equals("q")) {
System.out.println(hold);
break;
}
}
}
public static boolean checkInt(String s, int it){
Scanner scan = new Scanner(s.trim());
if(!scan.hasNextInt(it))
return false;
scan.nextInt(it);
return !scan.hasNext();
}
public static void main(String args[]) {
create();
}
}
任何輸入都會很棒。
可能重複http://stackoverflow.com/questions/13102045/skipping-nextline-after-use -nextint) – 2015-01-27 00:40:15
@AlexisKing我在程序中看不到任何nextLine() – kirbyquerby 2015-01-27 00:41:25
當我使用.nextLine()時,通常會發生同樣的事情; – Matt 2015-01-27 00:41:51