我正在尝试使用 Scanner 对象来读取键盘输入(双类型数字)。程序可以编译,但它只能接受两个数字。下面是我的代码,请帮我找出原因。谢谢!
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
ArrayList<String> container = new ArrayList<String>();
double number = 0;
System.out.println("Type in the polynomials in increasing powers:");
while (!keyboard.nextLine().isEmpty())
{
// number = keyboard.nextDouble();
try {
number = keyboard.nextDouble();
} catch(Exception e) // throw exception if the user input is not of double type
{
System.out.println("Invalid input");
}
container.add("-" + number);
}