我不确定如何让我的代码正确输出正确的输出。以下是我迄今为止Java变量可能未被初始化
import java.util.Scanner;
public class ComputeTax {
public static void main(String[] args) {
System.out.print("Taxable Income Single Married Jointly Married Seperate Head of House");
System.out.print("\n\n-----------------------------------------------------------------------------------");
int status;
double income;
double tax = 0;
for(income = 50000; income <= 60000; income+=50)
{
if (status == 50000)
{
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) { // Compute tax for married file jointly
// Left as exercise
}
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
}
// Display the result
System.out.println("Tax is " + (int)(tax * 100)/100.0);
}
}
}
样本输出是:
Taxable Income Single Married Married Seperate Head of House
50000 8688 6665 8688 7352
50050 8700 6673 8700 7365
...
59950 11175 8158 11175 9840
60000 11188 8165 11188 9852
我相信我的“for循环”是正确的,我只是不知道我的计算,以及如何将它们全部打印出来。目前,我收到错误:
variable status might not have been initialized
问题是什么?你能举一个当前输出的例子吗? –
我现在有一个错误与我的“如果声明说变量状态可能尚未初始化 – Tanner10
@ Tanner10首先在谷歌链接”变量未初始化的Java“http://stackoverflow.com/questions/2448843/variable-可能未被初始化错误 – sashkello