【发布时间】:2015-05-25 14:37:40
【问题描述】:
我想在我的代码中手动读取一些值。它适用于除最后一个(lambda2)之外的所有值。我可以无限地继续输入值,即使它们不是双精度值,也不会发生任何事情。如果我使用任何其他值键入其他内容,我会收到一条错误消息,以及我第一次输入 lambda2。我在另一个代码中以类似的方式(最终只创建一个不同的对象)做了它,它工作得很好。
System.out.print("All the asked input must be divided by 'Enters' \n");
Scanner userinput = new Scanner(System.in);
double b1;
double b2;
System.out.print("Enter the backlog costs for product 1 and 2: \n");
b1 = userinput.nextDouble();
b2 = userinput.nextDouble();
double h0;
double h1;
double h2;
System.out.print("Enter the holding costs for components 0, 1 and 2: \n");
h0 = userinput.nextDouble();
h1 = userinput.nextDouble();
h2 = userinput.nextDouble();
double lambda1;
System.out.print("Enter the demand rate of product 1: \n");
lambda1 = userinput.nextDouble();
double lambda2;
System.out.print("Enter the demand rate of product 2: \n");
lambda2 = userinput.nextDouble();
userinput.close();
double c1 = b1 + h0 + h1;
double c2 = b2 + h0 + h2;
SP solvable = new SP( b1, b2, h0, h1, h2, lambda1, lambda2, c1, c2);
return solvable;
【问题讨论】:
-
你应该使用 Ctrl+D 关闭输入流...
-
你尝试了哪些数字?
标签: java