2014-09-25 95 views
-4

這是我正在處理的任務。不良操作數類型一元運算符'+++'的字符串

我得到的,對於一元運算符壞數類型字符串「+++」第12行

我不知道如何解決這個問題。我實際上是直接從我的書中複製它...這意味着我花了150美元的質量差。但那不是在這裏或那裏。請幫忙。

import java.util.Scanner; 

public class ComputeTax { 

public static void main(String[] args) { 
// Create a Scanner 
Scanner input = new Scanner(System.in); 

// Prompt the user to enter filing status 
System.out.print(
    "(0-single filer, 1-married jointly or qualifying widow(er)", 
    + "\n2-married separately, 3-head of household)\n" + 
    "Enter the filing status: "); 
int status = input.nextInt(); 

// Prompt the user to enter taxable income 
System.out.print("Enter the taxable income: "); 
double income = input.nextDouble(); 

// Compute tax 
double tax = 0; 

if (status == 0) {// Compute tax for single filers 
    if (income <= 8350) 
      tax = income * 0.10; 
    else if (income <= 33950) 
      tax = 8350 * 0.10 + (income - 8350) * 0.15; 
    else if (income <= 82250) 
      tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + 
     (income - 33950) * 0.25; 
    else if (income <= 171550) 
      tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + 
     (82250 - 33950) * 0.25 + (income - 82250) * 0.28; 
    else if (income <= 372950) 
      tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + 
      (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 + 
      (income - 171550) * 0.33; 
    else 
      tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + 
     (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 + 
     (372950 - 171550) * 0.33 + (income - 372950) * 0.35; 
} 
else if (status == 1) { 
// Left as exercise 
// Compute tax for married file jointly or qualifying widow(er) 
} 
else if (status == 2) { 
// Compute tax for married separately 
// Left as exercise 
} 
else if (status == 3) { 
// Compute tax for head of household 
// Left as exercise 
} 
else { 
    System.out.println("Error: invalid status"); 
    System.exit(1); 
} 
// Display the result 
System.out.println("Tax is " + (int)(tax * 100)/100.0); 

} 

}

+1

我覺得你的書就好了。 – Qix 2014-09-25 19:07:12

回答

5

刪除,,它會正常工作

System.out.print(
     "(0-single filer, 1-married jointly or qualifying widow(er)" 
    + "\n2-married separately, 3-head of household)\n" + 
    "Enter the filing status: "); 
1

您有一個額外的逗號。

"widow(er)", 
4
"(0-single filer, 1-married jointly or qualifying widow(er)", 
                   ^---stray comma 
    + "\n2-married separately, 3-head of household)\n" + 
相關問題