Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question