我收到此 block 的“非法类型开始”错误:
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/