2015-09-07 26 views
-3

我得到這個代碼的錯誤:是非法類型的開始。非法開始類型 - 括號

我無法弄清楚在何處放置支架下面的代碼:

import java.util.Scanner; public class TaxCalculator { 
public static void main(String [] args) 
{ 
    Scanner keyboard = new Scanner(System.in); 
    System.out.println("What is your income?"); 
    double income; //Income 
    income = keyboard.nextDouble(); 
    System.out.println("How many dependents are in your household?"); 
    int dependents; //Dependents 
    dependents = keyboard.nextInt(); 
} 
public static void sd(); 
int singleyes = 5950; 
int singleno = 11900; 
boolean single = true; 
if (single = yes) 
     StandardDeduction = 'yes'; 
    } else if (single = no) { 
     StandardDeduction = 'no'; } 
+0

你的'sd()'方法聲明幾乎看起來像一個C/C++函數原型。 –

回答

1

sd方法的聲明是不正確。布爾永遠不會是yesnoString(s)被雙引號包圍。這

public static void sd(); 

應該像

public static String sd() { 
    int singleyes = 5950; 
    int singleno = 11900; 
    boolean single = true; 
    if (single) { 
     StandardDeduction = "yes"; 
    } else { 
     StandardDeduction = "no"; 
    } 
} 

最後,分號作爲空操作語句,不能出現一個聲明體外。