The problem is that readInt
does not behave as you might expect. It is not reading a string and convert the string to a number; it reads the input as *bytes:
Reads four input bytes and returns an int value. Let a-d be the first through fourth bytes read. The value returned is:
(((a & 0xff) << 24) | ((b & 0xff) << 16) | ((c & 0xff) << 8) | (d & 0xff))
This method is suitable for reading bytes written by the writeInt method of interface DataOutput.
In this case, if you are in Windows and input 12
then enter, the bytes are:
- 49 - '1'
- 50 - '2'
- 13 - carriage return
- 10 - line feed
Do the math, 49 * 2 ^ 24 + 50 * 2 ^ 16 + 13 * 2 ^ 8 + 10 and you get 825363722.
If you want a simple method to read input, checkout Scanner
and see if it is what you need.