gpt4 book ai didi

Java 乘法错误

转载 作者:行者123 更新时间:2023-12-02 03:55:22 26 4
gpt4 key购买 nike

需要帮助解决这个问题。

似乎无法弄清楚为什么补贴保费打印为 0。

import java.util.Scanner; 

public class qns1b
{
public static void main(String[]args)
{
Scanner kb = new Scanner(System.in);
System.out.print("Enter the age next birthday of the citizen: ");
int age = kb.nextInt();
System.out.print("Enter the annual value of residence: $ ");
double annualValue = kb.nextDouble();
System.out.print("Enter number of properties: ");
int noOfProperties = kb.nextInt();
System.out.print("Enter the monthly income: $ ");
double monthlyIncome = kb.nextDouble();

double subsidy = 0;

double annualPremiumBfoSubsidy = 0;
double annualPremium;
double subsidisedPremium = 0;
double subsidisedDeduction = 0;


subsidisedDeduction = annualPremiumBfoSubsidy*subsidy;
subsidisedPremium = annualPremiumBfoSubsidy-subsidisedDeduction;

//(ii)

if (age <= 20 && monthlyIncome <= 1100 && noOfProperties == 1)

{
subsidy = 0.25;
annualPremium = 50;
annualPremiumBfoSubsidy = 130;
System.out.println("Previous Premium: $" +annualPremium+ " " + "Current Premium: $" +annualPremiumBfoSubsidy);
System.out.println("Subsidised Premium: $" +subsidisedPremium+ " " +"(deduct $" +subsidisedDeduction+ "for 30% of" +annualPremiumBfoSubsidy+ ")");

}
else
{
System.out.print ("good");
}

}
}

最佳答案

它是两个设置为零的变量的差异。

 subsidisedPremium =   annualPremiumBfoSubsidy-subsidisedDeduction;

这两个变量之前都设置为零。

关于Java 乘法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35523549/

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