我對Java相對來說比較新,而且我決定製作這個程序,因爲開始學習如何玩方法似乎是一個足夠簡單的任務。無論如何,這是我的程序,因爲它現在。我收到錯誤錯誤:'.class'預計
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
任何幫助,將不勝感激
您的代碼在很多方面都是錯誤的,包括您定義的方法會返回smallAverage對象。重新閱讀關於如何創建方法的章節。 –