views:

314

answers:

1

I'm getting weird results from the System.out.print immediately below the Scanner declaration in the code snippet below. It seems like it's executing twice. I've debugged it and immediately after executing the print statement I get this in standard out:

run: Input a freaking binary number: Input a freaking binary number:

I added the "freaking" to verify it wasn't somehow entering the while loop print without me knowing.

For your info this is being executed in the netbeans IDE 6.7.1 on a 64 bit vista machine with the 64 bit JDK. Hopefully you can see the error of my ways!

Thanks!

Edit: When executing the Netbeans generated JAR file on the command line the statement only prints once. Has anyone encountered this kind of weird behavior in Netbeans that might know how I can prevent this from happening. I hate having to work outside my IDE during development cycles.

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());
    }
}
+3  A: 

The "2 space after :" in print(String s) bug in Netbeans?

In the line:

System.out.print("Input a freaking binary number: ");

delete the 2nd trailing space.

Ma3x
Holy crap you've got to be kidding me! This is it!
Brian
Do you know if this is going to be fixed any time soon?
Brian
very interesting i have never noticed this. going to have to replicate. i am oddly curious.
Berek Bryan
I was not aware of this bug in Netbeans, that's why my first line is a question, but I guess I wasn't clear enough on that :)@Brian: Maybe the Netbeans issue tracker might answer your question, however a quick search on the issue tracker returned no results for me.It seems this bug is related to how the Netbeans console handles the ': ' (semicolon, space, space) sequence. If you print() that sequence after some text (1 char or more) in the same line, the whole line (including any following text) will be duplicated and output one more time on the same line.
Ma3x