Q:

Unexpected result in simple java program

I am new to java and my problem is that the output is showing 2 numbers after I press a key and I can't understand why.
This is the code:
class ForTest {    
    public static void main(String args[]) throws java.io.IOException {
        int i;
        System.out.println("Press S to stop.");
        for(i = 0; (char) System.in.read() != 'S'; i++)
            System.out.println("Pass #" + i);
    }
}

A:

Although I cannot reproduce the issue: (See Here), my suggestion is to print out the character (as an integer) as well. This will help you debug:
for(i = 0; (char)( int c = System.in.read() ) != 'S'; i++)
   System.out.println("Pass #" + i + ": " + c);

