Java ProgramsControl FlowCalculate Income Tax

Calculate Income Tax in Java

intermediate·  Control Flow  ·  Conditional Statements

Problem

Progressive tax slabs tax only the portion of income that falls within each bracket, not the entire income at the top bracket's rate — this example uses simplified, illustrative slabs rather than any specific country's actual tax law.

Given an annual income, calculate the tax owed using a tiered slab structure.

Input
income = 800000
Output
Income tax: 72500.0

Java Program

Java
public class IncomeTaxCalculator { public static void main(String[] args) { double income = 800000; double tax; if (income <= 250000) { tax = 0; } else if (income <= 500000) { tax = (income - 250000) * 0.05; } else if (income <= 1000000) { tax = 12500 + (income - 500000) * 0.20; // 12500 is the tax already owed from the lower brackets } else { tax = 112500 + (income - 1000000) * 0.30; // 112500 is the tax already owed from every bracket below } System.out.println("Income tax: " + tax); } }

Output

Income tax: 72500.0

Core Logic

Each bracket only taxes the slice of income that falls above the previous bracket's boundary, so higher brackets add their rate on top of the tax already computed below them.

How It Works
  1. 1Income up to 250000 is untaxed, so tax stays 0 in that bracket.
  2. 2Income up to 500000 is taxed at 5%, but only on the portion above 250000.
  3. 3Income up to 1000000 adds a flat 12500 (the tax already owed from the lower brackets) plus 20% of the portion above 500000.
  4. 4Anything above 1000000 adds a flat 112500 plus 30% of the portion above that boundary.
For income = 800000, it falls in the third bracket: 12500 + (800000 - 500000) * 0.20 = 72500.
💡

Key Point: The flat amounts (12500, 112500) aren't arbitrary — they're the exact tax already accumulated from every bracket below, which is what makes this a genuine progressive calculation instead of a flat rate applied to the whole income.

Key Concepts

if / else ifprogressive slabsarithmetic

Related Programs