N
N
NoMoneyException2016-07-23 22:20:45
Java
NoMoneyException, 2016-07-23 22:20:45

How does System.in.read() work?

As I understand it, it returns the int-code of the number.
so I got the number itself.
int index = Character.getNumericValue(System.in.read());
but for some reason it still works crookedly for several digits (it seems that read () returns only 1 number). Are there better alternatives?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zhulikof, 2016-07-23
@eugene_leshchinskiy

It returns the character code read from the System.in stream.
If you enter the number 123, you will get the character code '1' - 49
Look at the Scanner, it allows you to wrap the stream and read primitive types and strings from it.

Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question