关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。
想改进这个问题?将问题更新为 on-topic对于堆栈溢出。
2年前关闭。
Improve this question
当我编译这个时,我得到一个错误,指出在 (String[] args) 之后需要一个分号。我无法绕过它。如果我添加一个,不出所料,我会得到 10 多个错误
导入 java.util.;
导入 java.text.;
公共(public)课PayCheck
{
private String givenName;
private double totalWage;
private double totalHours;
private double gross, netPay, tax, ssnTax;
static String employer="PrismHR";
static double taxRate = 0.22;
static double ssRate = 0.06;
public static void main (String[] args) PayCheck()
{
Scanner std = new Scanner(System.in);
System.out.println("Enter employee name: ");
givenName = std.nextLine();
System.out.println("Enter pay rate and hours worked: ");
totalWage = std.nextDouble();
totalHours = std.nextDouble();
gross = totalWage*totalHours;
tax = gross*taxRate;
ssnTax = gross*ssRate;
netPay = gross-tax-ssnTax;
}
public PayCheck(String name, double wage, double hours)
{
this.givenName = name;
this.totalHours = hours;
this.totalWage = wage;
gross = totalWage * totalHours;
tax = gross * taxRate;
ssnTax = gross * ssRate;
netPay = gross - tax - ssnTax;
}
public String toString()
{
String emptyString = "";
NumberFormat formats = new DecimalFormat(".##");
emptyString += "Employer: " + employer + "\n";
emptyString += "Employee: " + givenName +"\n";
emptyString += "Gross income: $" + formats.format(gross)+"\n";
emptyString += "Federal Tax: $" + formats.format(tax) + "\n";
emptyString += "Social Security Tax: $" + formats.format(ssnTax) +"\n";
emptyString += "Net Pay: " + formats.format(netPay);
return emptyString;
}
}
最佳答案
通常,这适用于所有编程语言,错误本身可能并不准确。在你的情况下,你有函数调用只是一种......在那里。
public static void main (String[] args) PayCheck()
{
...
}
摆脱
PayCheck()
.我不确定你想用它做什么,但这肯定会导致错误。
关于java - java方法中需要分号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60157252/