Image

Imagesamantharichter wrote in Imagejava_dev 😯confused

StdIn and while loops

Hello! Sorry to bother you again. While everything else works fine now, there is this little bit of code where I've been searching all day for the error, but just can't find it...

char i = StdIn.readChar();
while(i!='b')
{
System.out.println("Wrong Input! You wrote: " + i);
System.out.println("Try again: ");
i = StdIn.readChar();

}

If I type in the wrong character I want the Program to tell me this and let me enter another character. Should be really easy, but for some reason I get this:


Wrong Input! You wrote: r
Try again:
Wrong Input! You wrote:

Try again:
Wrong Input! You wrote:

Try again:



Any idea why Java is going through the loop several times before it let's me enter another character? I'm assuming the reason it really simple and I'm just to blind to see it...

Thanks in advance,
~Sam~

Edit: Solved the problem with your help! Thank you!!