我正在进行"非法的类型"这个块的错误:
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)
答案 0 :(得分:1)
我不知道为什么你的代码会出错,但你会像这样使用equalsIgnoreCase:
if (maritalStatus.equalsIgnoreCase("Single")) {
taxableIncome = grossIncome - deductions - dependents * allowance;
} else if (maritalStatus.equalsIgnoreCase("Married")) {
taxableIncome = grossIncome - deductions - (dependents + 2) * allowance;
}
我还拿出了你无关紧要的括号。