AcWing 672. 税 - Java
原题链接
简单
作者:
KYCygni
,
2021-03-12 04:58:16
,
所有人可见
,
阅读 308
Java 代码
import java.util.Scanner;
public class Main
{
public static double calcTax(double income, double base, double limit, double taxRate)
{
if (income - base > limit && limit > -1)
return limit * taxRate;
else
return (income - base )*taxRate;
}
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
double income = cin.nextDouble();
double tax = 0.0;
if (income > 2000)
tax += calcTax(income, 2000.0, 1000.0, 0.08);
if (income > 3000)
tax += calcTax(income, 3000.0, 1500.0, 0.18);
if (income > 4500)
tax += calcTax(income, 4500.0, -1, 0.28);
if (tax == 0.0)
System.out.println ("Isento");
else
System.out.println ("R$ " + String.format("%.2f", tax));
}
}