'Cannot enter input in multiple lines via command line for feeding Java code
I want to enter something like this on the command line as an input and process it in the Java code
21 4 -2 31 23 0 10 28 -6 19
1
5
20
8
0
But as soon as I push Enter the program starts executing and I cannot enter the next line.
How can I do it?
Solution 1:[1]
You can't process multi-line command line input. There can only be one.
If you want multiple lines, you'll have to read them in using a Scanner and parsing each one. You'll also need a condition to tell the program when you've entered the last line. You should do this in a while loop.
Solution 2:[2]
You could have something like "\n" when you write on the command line. Then program Java to process that as a new line accordingly.
For example, if you wanted the following.
a b c
1
2
3
You could enter the following.
a b c\n 1\n 2\n 3
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Peter Mortensen |
