gpt4 book ai didi

java - 嵌套的 If/Else 语句

转载 作者:行者123 更新时间:2023-12-02 07:57:26 25 4
gpt4 key购买 nike

很抱歉再次编辑此内容,但我不想再发一篇帖子,而是想在这里提问。

    public static void main(String[] args)
{
// TODO code application logic here

char response = 0;
double grossAnnualIncome = 0.0;
double annualTuition = 0.0;
double annualCharity = 0.0;
double homeMortgage = 0.0;
double healthCredit = 0.0;
double annualAfterTaxes = 0.0;
double monthlyAfterTaxes = 0.0;
double taxAt17 = 0.0;
double taxableIncome = 0.0;
double ans1 = 0.0;

Scanner input = new Scanner(System.in);

System.out.printf( "Please enter your gross annual income or 0 for none: " );
grossAnnualIncome = input.nextDouble();

if( grossAnnualIncome > 0 )
{
System.out.printf( "Please enter your annual tuition and expenses for higher education or 0 for none: ");
annualTuition = input.nextDouble();

System.out.printf( "Please enter your annual charitable contributions or 0 for none: ");
annualCharity = input.nextDouble();

System.out.printf( "Please enter the annual interest paid for your home mortgage or 0 for none: ");
homeMortgage = input.nextDouble();
input.nextLine();

System.out.printf( "Did you purchase health insurance through your employer or outside the workplace?"
+ " Enter 'Y' or 'N': ");
response = input.nextLine().charAt(0);


if( Character.toUpperCase(response) == 'Y' )
{
System.out.printf( "Are you filing as a family? Enter 'Y' or 'N': ");
response = input.nextLine().charAt(0);

if ( Character.toUpperCase(response) == 'Y' )
{
healthCredit = 3500;
}
else
{

if( Character.toUpperCase(response) == 'N' )
{
System.out.printf( "Are you filing as single? Enter 'Y' or 'N': ");
response = input.nextLine().charAt(0);
}
if( Character.toUpperCase(response) == 'Y')
{
healthCredit = 2000;
}

}

}
else
{
healthCredit = 0;
}

taxableIncome = grossAnnualIncome - homeMortgage - annualTuition - annualCharity - healthCredit;
taxAt17 = taxableIncome * .17;
annualAfterTaxes = grossAnnualIncome - taxAt17;
monthlyAfterTaxes = annualAfterTaxes / 12;
ans1 = homeMortgage + annualTuition + annualCharity + healthCredit;

System.out.printf( "\nYOUR TAXES\n\n"
+ "Gross Annual Income: %,.0f\n\n"
+ "Deductions: \n"
+ "\tHigher Education: %,.0f\n"
+ "\tCharitable Contributions: %,.0f\n"
+ "\tHome Mortgage Interest: %,.0f\n"
+ "\tHealth Insurance Tax Credit: %,.0f\n\n"
+ "Tax at 17%%: %,.0f\n"
+ "Annual Income After Taxes: %,.0f\n"
+ "Monthly Income After Taxes: %,.0f", grossAnnualIncome, annualTuition, annualCharity,
homeMortgage, healthCredit, taxAt17, annualAfterTaxes, monthlyAfterTaxes);


}

if( grossAnnualIncome <= 0 )
{
System.out.printf( "You earned no income so you owe no taxes!" );
}

System.exit(0);
}

}

我的两个输出都是正确的,但我的最后一个输出遇到了问题。

我的最后一个输出需要读取“您欠 0.00 美元税款!”

当我编码时:

if (grossAnnualIncome <= ans1)
{
System.out.printf( "YOU OWE $0.00 IN TAXES!" );
}

它显示了grossAnnualIncome > 0 输出的所有内容。

最佳答案

Java: Literal percent sign in printf statement

这可能与 17% 的百分比有关。它需要转义,可以用另一个 % 来完成

17%%

关于java - 嵌套的 If/Else 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9425610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com