我收到此块的“非法开始类型”错误:

if (maritalStatus.equals("Single") || maritalStatus.equals("single")){
        taxableIncome = grossIncome - deductions - (dependents * allowance);
} else if (maritalStatus.equals("Married") || maritalStatus.equals("married")){
        taxableIncome = grossIncome - deductions - ((dependents + 2) * allowance);
}


另外,对于单身/单身和已婚/已婚,我该如何使用以下声明?

Boolean equalsIgnoreCase (String thisString)

最佳答案

我不知道为什么您的代码出错,但是您将使用equalsIgnoreCase这样:

if (maritalStatus.equalsIgnoreCase("Single")) {
    taxableIncome = grossIncome - deductions - dependents * allowance;
} else if (maritalStatus.equalsIgnoreCase("Married")) {
    taxableIncome = grossIncome - deductions - (dependents + 2) * allowance;
}


我还拿出了你多余的括号。

关于java - 非法启动类型错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26186270/

10-10 03:02