My requirement is to take multiple inputs from user on multiple lines.
Each line signifies inputs with meanings of : Power Energy Idea Strength
each separated by just one space.
Input:
2 4 5 7
3 4 8 1
4 2 3 6
Output consists of List:
List<Integer> power = {2,3,4}
List<Integer> energy = {4,4,2}
List<Integer> idea = {5,8,3}
List<Integer> strength = {7,1,6}
preferred solution is in Java, but if Java-8 solutions can be given i would love it.
i have tried so far as below but no luck:
String input = "";
Scanner keyboard = new Scanner(System.in);
String line;
while (keyboard.hasNextLine()) {
line = keyboard.nextLine();
if (line.isEmpty()) {
break;
}
input += line + "\n";
}
System.out.println(input);
i am able to read input in multiple lines but not able to save them as separate category in List
.