0
public class Practice {
    public static void main(String []args)
    throws IOException{
        char ch;
        int xh;
        ch=(char)System.in.read();
        xh=System.in.read();
        System.out.println(ch);
        System.out.println(xh);
    }
}

If it puts an input of 1 in for, the char value in the System.in.read(); will use that value for the xh.

For instance, if I put 1 in it, it will automatically give 1, 10 and will not give me an option to input my int value.

Why is that? Also, I know I can use a scanner instead, but I don't want to.

Unheilig
  • 16,196
  • 193
  • 68
  • 98
Eli
  • 827
  • 1
  • 7
  • 21
  • Consider `int i = 'a';`, does that help? – Elliott Frisch Feb 10 '16 at 01:39
  • no , also I dont really follow ur logic, you setting an int to a char value? System.in.read(); already by default returns an int value – Eli Feb 10 '16 at 01:58
  • 1
    See http://stackoverflow.com/questions/15273449/what-does-system-in-read-actually-return `10` is the `CR` after the `1` in your input stream. – adamdc78 Feb 10 '16 at 02:28
  • And not a `char`. I don't follow your question. You call `read` twice. What are you trying to do? – Elliott Frisch Feb 10 '16 at 02:28
  • System.in.read(); is basically the same as the scanner, hence, it create a line for input. I called it twice , because in the first input I want the user to put a char in and the second line I want them to put an int in – Eli Feb 10 '16 at 03:59

0 Answers0