English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

我有個類似數學計算的Java題目..因為不是那錯就是這錯..實在不知該怎辦..
請各位大大救救我...
關於價錢計算問題..他分五小題..
(1)輸入收入..(income)
(2)收入三十萬以下,6%的稅金
(3)收入三十萬~八十萬,13%的稅金
(4)收入八十萬~二百萬,21%的稅金
(5)收入二百萬以上,30%的稅金
可能真的很簡單..但我只是初學者~~真的很急!謝謝~~~
可以幫我寫出程式嗎@@..謝謝~~

2006-08-06 09:35:03 · 3 個解答 · 發問者 花花兒 1 in 電腦與網際網路 程式設計

3 個解答

//Power by Eclipse SDK//檔案名與類別名大小寫相同import java.util.Scanner;public class J_test {//檔案名 J_test.java public static void main(String[] args) {  //=====MAIN STATEMENT=====//  double dblMoney,dblTemp,dblTax;  Scanner input=new Scanner(System.in);  System.out.printf("Input Money: ");  dblMoney=input.nextDouble();  dblTemp=dblMoney/10000;  //dblMoney 收入  //dblTax 稅金   if(dblTemp>0){   if(dblTemp<30){//30萬    dblTax=dblMoney*6/100;   }else if(dblTemp<80){//80萬    dblTax=dblMoney*13/100;   }else if(dblTemp<200){//200萬    dblTax=dblMoney*21/100;   }else{//200萬以上    dblTax=dblMoney*30/100;   }   System.out.printf("Money: %.2f dollars.\n",dblMoney);   System.out.printf("Tax: %.2f dollars.\n",dblTax);  }else{//負數是錯誤的輸入   System.out.printf("Incorrect Input!\n");  }  //=====MAIN END=====// }}

2006-08-06 11:05:43 · answer #1 · answered by Big_John-tw 7 · 0 0

超酷的

2006-09-02 13:57:15 · answer #2 · answered by lucas 2 · 0 0

我假定你使用的是文字介面(command line interface),所以採用以下方法
只要讀取使用者打入的字串,轉成數值後就可以計算
省下的就是if,else if判斷這個數值落在哪個範圍了
在文字介面下讀取輸入的字串可以用
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
意思就是把System.in物件"包"成InputStreamReader物件
再把InputStreamReader物件"包"成BufferedReader物件
包這麼多層無非就是要利用BufferedReader物件中的readLine(),好一次讀取一行
然後我用Double.valueOf()把輸入的字串轉成double好來計算
import java.io.*;
import java.lang.*;

public class ReadString {

public static void main (String[] args) {

// prompt the user to enter their income
System.out.print("Enter your income: ");

// open up standard input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
double income=0;
String userIncome = null;
// read the username from the command-line; need to use try/catch with the
// readLine() method
try {
userIncome = br.readLine();
income=Double.valueOf(userIncome);
} catch (IOException ioe) {
ioe.printStackTrace();
System.exit(1);
}
System.out.println("Your income is "+income);
if(income>0&&income<=300000){System.out.println("Your rax is "+income*0.06);}
else if(income>300000&&income<=800000)System.out.println("Your rax is "+income*0.13);
else if(income>800000&&income<=2000000)System.out.println("Your rax is "+income*0.21);
else if(income>2000000)System.out.println("Your rax is "+income*0.30);
}

} // end of ReadString class

2006-08-06 15:17:52 補充:
sorry~有錯字,是tax不是rax啊

2006-08-06 11:13:50 · answer #3 · answered by OliverT 1 · 0 0

fedest.com, questions and answers