我从下面的代码片段中的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