我是Java的初学者,我的教授希望我们创建一个涉及数学的程序。问题是他想要一个单独的方法进行计算。有人可以帮帮我吗。由于某种原因,程序不会运行结果。我试着环顾这个网站,找不到答案。以下是代码:
import javax.swing.JOptionPane;
public class forFun {
public static void main(String[] args)
{
double x, y, z;
String xVal, yVal, zVal;
xVal = JOptionPane.showInputDialog("Enter first integer: ");
yVal = JOptionPane.showInputDialog("Enter second integer: ");
zVal = JOptionPane.showInputDialog("Enter third integer: ");
x = Double.parseDouble(xVal);
y = Double.parseDouble(yVal);
z = Double.parseDouble(zVal);
System.exit(0);
}
public static void sumOfStocks(double x, double y, double z)
{
double result = x * y * z;
System.out.println("The product of the integers is: " + result);
System.exit(0);
}
}
答案 0 :(得分:1)
以下是代码应该如何
的示例import javax.swing.JOptionPane;
public class forFun {
public static void main(String[] args)
{
double x, y, z;
String xVal, yVal, zVal;
xVal = JOptionPane.showInputDialog("Enter first integer: ");
yVal = JOptionPane.showInputDialog("Enter second integer: ");
zVal = JOptionPane.showInputDialog("Enter third integer: ");
x = Double.parseDouble(xVal);
y = Double.parseDouble(yVal);
z = Double.parseDouble(zVal);
double result = sumOfStocks(x, y, z);
System.out.println("The result is %d", result);
System.exit(0);
}
public static double sumOfStocks(double x, double y, double z)
{
double result = x * y * z;
return result;
}
}