我 运行 的分配在第一个 InputDialog 后停止工作,我该如何修复它?
Assignment that I ran stops working after first InputDialog, how could I fix it?
import javax.swing.JOptionPane;
import java.util.Scanner;
public class ShippingCost
{
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
JOptionPane.showInputDialog("Please enter the length of your package: ");
double length=input.nextDouble();
JOptionPane.showInputDialog("Please enter the width of your package: ");
double width=input.nextDouble();
JOptionPane.showInputDialog("Please enter the height of your package: ");
double height=input.nextDouble();
double dimensions= length * width * height;
System.out.println("The total dimensions of your package is: " + dimensions);
double charge=0;
double surcharge;
double additionalCharge;
double totalCost;
代码编译得很好,但是 运行将它作为一个应用程序来测试输入是我 运行 遇到的问题。第一个输入框出现,然后在点击回车后不会做任何其他事情。我是 Java 的超级新手,只停留在这个...
您应该使用 JOptionPane.showInputDialog
的 return 值来获取用户的输入,例如
double length = Double.valueOf(JOptionPane.showInputDialog("Please enter the length of your package: "));
等等。
import javax.swing.JOptionPane;
import java.util.Scanner;
public class ShippingCost
{
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
JOptionPane.showInputDialog("Please enter the length of your package: ");
double length=input.nextDouble();
JOptionPane.showInputDialog("Please enter the width of your package: ");
double width=input.nextDouble();
JOptionPane.showInputDialog("Please enter the height of your package: ");
double height=input.nextDouble();
double dimensions= length * width * height;
System.out.println("The total dimensions of your package is: " + dimensions);
double charge=0;
double surcharge;
double additionalCharge;
double totalCost;
代码编译得很好,但是 运行将它作为一个应用程序来测试输入是我 运行 遇到的问题。第一个输入框出现,然后在点击回车后不会做任何其他事情。我是 Java 的超级新手,只停留在这个...
您应该使用 JOptionPane.showInputDialog
的 return 值来获取用户的输入,例如
double length = Double.valueOf(JOptionPane.showInputDialog("Please enter the length of your package: "));
等等。