1
1
12_server2021-09-16 18:25:56
Java
12_server, 2021-09-16 18:25:56

Java Scanner. How to read data?

Reverse
I need to make a Reverse class that reads numbers from stdin and prints them to stdout in reverse order. As input, the program receives integers separated by a space.
Input example:
1 3
3

How to correctly read these characters through Scanner?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mimocodil, 2021-09-16
@12_server

If no arithmetic is required, then you can just read nextLine() and then get an array of substrings by splitting the string on spaces with split(), and then output them in reverse order.
If you still need numbers, you can read them using the nextInt() method, or take the resulting substrings and convert each to an integer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question