I am trying to get a while loop to break by pressing the Enter key on a keyboard. My code is:
package javaapplication4;
import java.util.ArrayList
I myself like to use try { ... } catch (NumberFormatException) so when you get a blank line (ie enter) your catch block is activated and you've escaped the loop
try {
while (true) {
System.out.println("Please enter the numbers seperated by a space: ");
numbers.add(keyboard.nextDouble());
//want the while loop to break here by pressing "enter" after entering array values
}
} catch (NumberFormatException ex) {}
System.out.println(numbers);