我從下面的代碼片段中的Scanner聲明正下方的System.out.print中得到奇怪的結果。它似乎是執行兩次。我已經調試它,並執行打印語句後立即我得到這個標準出來:奇怪的System.out.print在Netbeans中的行爲
運行: 輸入一個嚇壞二進制數:輸入一個嚇壞二進制數:
我添加了「該死的」驗證沒有我知道的時候,它不會以某種方式進入while循環打印。
對於您的信息,這是在NetBeans IDE 6.7.1中使用64位JDK在64位vista機器上執行的。希望你能看到我的方式錯誤!
謝謝!
編輯:在命令行上執行Netbeans生成的JAR文件時,語句只打印一次。有沒有人在Netbeans中遇到這種奇怪的行爲,可能知道我可以如何防止這種情況發生。我討厭在開發週期內在IDE外工作。
private void getInput()
{
Scanner scanner = new Scanner(System.in);
System.out.print("Input a freaking binary number: ");
// Grab the next inputed long and save it in the currentValueInBinary
// member variable
setCurrentValueInBinary(scanner.nextLong());
// Loop until a valid binary number is retrieved
while (!isNumberBinary(currentValueInBinary))
{ // Input was negative, report error and re-request input
System.out.println("Input must be a Binary value");
System.out.print("\nInput a binary number: ");
setCurrentValueInBinary(scanner.nextLong());
}
}
如果直接從命令行執行它,你會得到相同的結果嗎?如果你可以將它重構成一個簡短的*完整的*程序,那麼這將使它更容易調試。 – 2009-10-16 14:33:59
它在使用Netbeans生成的JAR的命令行上正常工作。所以在我看來,這是一個Netbeans問題。我仍然想弄清楚,但至少我們已經把它縮小了! – Brian 2009-10-16 14:46:18