-1
import java.util.*;
import java.math.*;
public class Arithmectic {
double mealCost;
int tipPercent;
int taxPercent;
public Arithmectic(double inMeal, int inTip, int inTax){
Scanner scan = new Scanner(System.in);
inMeal = scan.nextDouble();
mealCost = inMeal;
inTip = scan.nextInt();
tipPercent = inTip;
inTax = scan.nextInt();
taxPercent = inTax;
}
public void printValues(){
System.out.println(mealCost);
System.out.println(tipPercent);
System.out.println(taxPercent);
}
public static void main(String[] args) {
Arithmectic rest = new Arithmectic(mealCost, tipPercent, taxPercent);
}
}
**上午有有一個問題算術靜態變量錯誤
Arithmectic rest = new Arithmectic(mealCost, tipPercent, taxPercent);
有人可以幫我解釋一下爲什麼我有這個錯誤我?**
'新Arithmectic(mealCost,tipPercent,taxPercent);'這些變量you're試圖傳遞'Arithmetic'的類成員,並且好像不存在於'public static main(String [])'範圍內。您應該重新設計'Arithmectic'構造函數,以便不用掃描器輸入變量,而只需指定parametr =>類成員。另一種方法應該實際讀取輸入,並將它讀取的值作爲參數傳遞給構造函數。 – SomeJavaGuy