【发布时间】:2016-02-22 21:37:49
【问题描述】:
我试图通过按键盘上的 Enter 键来中断 while 循环。我的代码是:
package javaapplication4;
import java.util.ArrayList;
import java.util.Scanner;
public class JavaApplication4 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
ArrayList<Double> numbers = new ArrayList( );
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
}
System.out.println(numbers);
}
【问题讨论】: