这是我的代码,计算税法中的循环只会返回第一个nmber甚至不正确。我怎样才能返回正确的值。在每个循环中,必须选择一种类型的税级,您输入的数字为1-4。这也将转到方法循环。
public class TaxTable
{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println(" Enter in status\n (1 for single\n,2 for married joint, 3 for Married separate, 4 for Head of House: ");
int status = scan.nextInt();
//if status to print out status name
if (status == 1)
System.out.println ("Taxable\t single\nIncome");
else if (status == 2)
System.out.println ("Taxable\tMarried Jointly\nQualified Widow\nIncome");
else if (status == 3)
System.out.println ("Taxable\tMarried separate\nIncome");
else if (status == 4)
System.out.println ("Taxable\tHead of House\nIncome");
int taxableIncome = 50000;
for (int i = 50000; i <= 60000; i += 50)
System.out.println (i + "\t" + Math.round(computeTax(status, taxableIncome)));
}
public static double computeTax (int status, double taxableIncome) {
double tax=0;
for (int k = 50000; k <= 60000; k =+ 50) {
if (status == 1)
taxableIncome = 4675 + ((k-33950)*.25);
else if(status == 2)
taxableIncome = 16701 + (k-16701)*.15;
else if(status == 3)
taxableIncome = 4675 + (k-33951)*.25;
else if(status == 4)
taxableIncome = 6227.5 + (k-33549)*.25;
return taxableIncome[k];
}
}
}
答案 0 :(得分:-1)
To&#34; return&#34;不使用数组的多个值,在方法中设置全局变量,然后返回第二个值。这是一些概念代码。
public static double returnVal2;
public static void method(){
double returnVal1 = otherMethod();
// returnVal1 now holds 1 return value, and returnVal2 now holds the other.
}
public static double otherMethod(){
returnVal2 = 0; // Change 0 to second value that you want to return.
return 0; // Change 0 to the first value that you want to return.
}