Loading...
Loading...
A simple tax calculator uses these slabs on yearly income:
Each rate applies only to the part of the income inside its slab. For example, on ₹7,50,000 the tax is 5% of 3,00,000 plus 10% of 1,50,000 = 15000 + 15000 = 30000.
Read the income and print the tax in whole rupees, dropping any paise.
Tax: X.Example 1
Input
750000
Output
Tax: 30000
The worked example from the statement.
Example 2
Input
1000000
Output
Tax: 60000
15000 + 30000 + 15% of 1,00,000 = 60000.
Try the problem first. Open one hint at a time.
Write the tax on a full slab once: 5% of 3,00,000 is 15000, 10% is 30000, 15% is 45000 and 20% is 60000.
In an else-if ladder from the top slab down, each branch is: tax on all the lower slabs + rate × (income − start of this slab) ÷ 100.
Use long: 30% of 10^12 does not fit in an int. Doing the multiplication before the division keeps the result exact until the paise are dropped.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor