[英]Cannot find symbol in a method in Java
嘗試計算聯邦稅時出現錯誤。 但是它說它找不到符號。 我嘗試了不同的方法,但是仍然遇到相同的錯誤。 任何幫助,將不勝感激。
public class calculatetax {
public static void main( String[ ] args) {
Scanner kb = new Scanner(System.in);
int employeehr = 0;
int ratehr = 0;
String stateresidence = "";
String maritalstatus = "";
System.out.println( " Employee Hours pls " ) ;
employeehr = kb.nextInt();
System.out.println( " Hourly Rate " ) ;
ratehr = kb.nextInt();
System.out.println( " State of residence" ) ;
stateresidence = kb.nextLine();
System.out.println( "Marital Status" ) ;
maritalstatus = kb.nextLine();
int wages = calculatewages(employeehr,ratehr);
calculatefedax(wages,maritalstatus);
}
public static int calculatewages( int n1, int n2 ) {
int wages = n1 * n2;
System.out.println("Return Wages" + wages);
return wages;
}
public static double calculatefedtax(double fedtax, str maritalstatus) {
if(maritalstatus.equals("marry"))
{
fedtax = fedtax * .20;
}
else if (maritalstatus.equals("single"))
{
fedtax = fedtax * .25;
}
else
{
fedtax = fedtax * .22;
}
return fedtax;
}
}
int wages
String maritalstatus
calculatefedax(wages,maritalstatus)
calculatefedtax(double fedtax, str maritalstatus)
看到問題了嗎?
您沒有適合int
+ String
參數的方法。 並且str
應該是String
。
哦,您的方法名稱中似乎有一個錯字。 這就是為什么它告訴您在那條線上找不到符號的原因。
您寫了str而不是String。 您還忘記了導入掃描儀。 最后,您找出了聯邦稅,但是卻什么也沒做。
calculatefedax(wages,maritalstatus);
那應該像
String fedtax = calculatefedax(wages,maritalstatus);
固定碼
import java.util.Scanner;
public class calculatetax {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int employeehr = 0;
int ratehr = 0;
String stateresidence = "";
String maritalstatus = "";
System.out.println(" Employee Hours pls ");
employeehr = kb.nextInt();
System.out.println(" Hourly Rate ");
ratehr = kb.nextInt();
System.out.println(" State of residence");
stateresidence = kb.nextLine();
System.out.println("Marital Status");
maritalstatus = kb.nextLine();
int wages = calculatewages(employeehr, ratehr);
double fedtax = calculatefedtax(wages, maritalstatus);
System.out.println("Fedtax:" + fedtax);
}
public static int calculatewages(int n1, int n2) {
int wages = n1 * n2;
System.out.println("Return Wages" + wages);
return wages;
}
public static double calculatefedtax(double fedtax, String maritalstatus) {
if (maritalstatus.equals("marry")) {
fedtax = fedtax * .20;
} else if (maritalstatus.equals("single")) {
fedtax = fedtax * .25;
} else {
fedtax = fedtax * .22;
}
return fedtax;
}
}
編輯:正如耶洛恩·范內維爾(Jeroen Vannevel)所指出的,我完全想念您在做完時忘記了t
calculatefedax(wages,maritalstatus);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.