Scanner s = new Scanner(System.in);
List<Integer> solutions = new LinkedList<>();
int o = 0;
while (o != 10) { // I want to read 2 numbers from keyboard
int p = s.nextInt(); // until send and enter, this is where is my
int c = s.nextInt(); //doubt
int d = p + c;
solutions.add(d);
o = System.in.read();
}
Iterator<Integer> solution = solutions.iterator();
while (solution.hasNext()) {
int u = solution.next();
System.out.println(u);
}
The problem that I have is, how I could send an enter for end the loop? because the System.in.read() takes the first number if I put another 2 numbers and example could be,
entries:
2 3 (enter) read 2 numbers and sum
1 2 (enter) read 2 numbers and sum
(enter) and here end the loop because of the enter and no numbers and gave the solutions
exits:
5
3
I don't know uf I posted well before