我对 Java 比较陌生,所以我决定制作这个程序,因为开始学习如何使用方法似乎是一项足够简单的任务。无论如何,这是我现在的程序。
import javax.swing.JOptionPane;
public class smallAverage{
public smallAverage getsmall() {
String sd1 = JOptionPane.showInputDialog("What is the first number?");
double sdx = Double.parseDouble (sd1);
String sd2 = JOptionPane.showInputDialog("What is the second number?");
double sdy = Double.parseDouble (sd2);
String sd3 = JOptionPane.showInputDialog("What is the third number?");
double sdz = Double.parseDouble (sd3);
return double sdx;
return double sdy;
return double sdz;
}
public smallAverage getavg() {
String ad1 = JOptionPane.showInputDialog("What is the first number");
double adx = Double.parseDouble (ad1);
String ad2 = JOptionPane.showInputDialog("What is the second number");
double ady = Double.parseDouble (ad2);
String ad3 = JOptionPane.showInputDialog("What is the third number");
double adz = Double.parseDouble (ad3);
return double adx;
return double ady;
return double adz;
}
public smallAverage work() {
double small = Math.min(sdx, sdy, sdz);
double avg = (adx + ady + adz) / 3;
System.out.println("The smallest of "+ sdx+ sdy+ sdz+ " is " + small + ", and the average of"+ adx+ ady+ adz+ " is "+ avg+ ".");
}
}
这里发生的实际数学对我来说真的没有任何意义,它是我想学习的代码的工作方式。我尝试过用许多不同的方式重写这段代码,但这似乎是最接近正确的。我只是不知道为什么它不起作用。当我尝试通过终端编译时,我得到了这个:
smallAverage.java:12: error: '.class' expected
return double sdx;
^
smallAverage.java:13: error: '.class' expected
return double sdy;
^
smallAverage.java:14: error: '.class' expected
return double sdz;
^
smallAverage.java:27: error: '.class' expected
return double adx;
^
smallAverage.java:28: error: '.class' expected
return double ady;
^
smallAverage.java:29: error: '.class' expected
return double adz;
^
6 errors
任何帮助将不胜感激