所得稅一般是以累進稅率來計算. 假設各級距之金額和稅率如下:
{300000, 400000, 500000, 600000, 800000, 其他所得}
{0.0, 0.06, 0.13, 0.21, 0.30, 0.45}
則若所得為2000000, 則其應繳稅款為:
0.0*300000 + 0.06*400000 + 0.13*500000 + 0.21*600000 +0.3*200000 = ?
若計算的結果有小數點, 則做四捨五入.
請寫一計算所得稅的程式, 能從鍵盤讀入今年之所得, 並將應繳的所得稅印在螢幕上.
請注意, 程式越簡潔, 並能藉修改資料來更動級距和稅率, 而能正確執行者, 則分數越高.
範例程式如下:

/*
 * Program Name: Tax.java
 * Purpose: 計算所得稅(程設二作業)
 * Author: Shiuh-Sheng Yu
 *         Department of Information Management
 * Since: 2000/03/24
 */
import java.io.*;
public class Tax {
    public static long calTax(long income) {
        // fill in the right answer
        //return yourResult;
    }
    public static long readIncome(InputStreamReader in) {
        StringBuffer sb = new StringBuffer();
        long income = 0;
        char c;
        try {
            while ((c=(char)in.read())!='\n' && c!='\r') {
                sb.append(c);
            }
            income = Long.valueOf(sb.toString()).longValue();
        } catch(IOException ioe) {
            System.out.println("讀入錯誤");
        } catch(NumberFormatException nfe) {
            System.out.println("格式錯誤:資料不為整數");
        }
        return income;
    }
    public static void main(String[] argv) {
        InputStreamReader in = new InputStreamReader(System.in);
        System.out.print("請輸入您今年的所得:");
        long income = readIncome(in);
        System.out.println("您今年需繳的所得稅為:"+calTax(income)+"元");
    }
}
網站範例區有完整的解答