Anonymous

# 超急件...一Java程式題目求解

http://img43.imageshack.us/img43/3333/asdumx.jpg

BigDecimal b1 = new BigDecimal(“0.01”); //產生0.01 的BigDecimal 物件

BigDecimal b2 = new BigDecimal(“0.09”); //產生0.09 的BigDecimal 物件

System.out.println(result); //輸出結果

divide(BigDecimal divisor, int scale, RoundingMode roundingMode)

http://img43.imageshack.us/img43/7814/assitg.jpg

A、B 值以及運算模式為使用者所輸入(包括除法的小數點位數)

Rating
• CK
Lv 4

import java.io.*;

import java.math.*;

public class BigDecimalOperation {

public BigDecimalOperation() {

}

public void plus(double a1, double a2) {

BigDecimal b1 = new BigDecimal(a1);

BigDecimal b2 = new BigDecimal(a2);

out(a1+" + "+a2+" = "+rst);//輸出結果

}

public void minus(double a1, double a2) {

BigDecimal b1 = new BigDecimal(a1);

BigDecimal b2 = new BigDecimal(a2);

BigDecimal rst = b1.subtract(b2);

out(a1+" - "+a2+" = "+rst);//輸出結果

}

public void multiply(double a1, double a2) {

BigDecimal b1 = new BigDecimal(a1);

BigDecimal b2 = new BigDecimal(a2);

BigDecimal rst = b1.multiply(b2, new MathContext(BigDecimal.ROUND_HALF_UP));

out(a1+" * "+a2+" = "+rst);//輸出結果

}

public void divide(double a1, double a2, int scale) {

BigDecimal b1 = new BigDecimal(a1);

BigDecimal b2 = new BigDecimal(a2);

BigDecimal rst = b1.divide(b2, scale, BigDecimal.ROUND_HALF_EVEN);

out(a1+" / "+a2+" = "+rst);//輸出結果

}

... ... ...

2009-06-04 04:59:57 補充：

too bad, can't post all of the content.

2009-06-04 05:03:05 補充：

public void doOperation() throws Exception {

out("請輸入兩個數字: (整數或浮點數皆可) ");

System.out.print("A = ");

System.out.print("B = ");

2009-06-04 05:03:44 補充：

System.out.print("請輸入運算模式: (+ - * /): ");

if(operator.equals("+")){

this.plus(a1, a2);

} else if(operator.equals("-")){

this.minus(a1, a2);

} else if(operator.equals("*")){

this.multiply(a1, a2);

}

2009-06-04 05:04:47 補充：

} else if(operator.equals("/")){

System.out.print("小數點位數 ");

this.divide(a1, a2, scale);

}

br.close();

}

2009-06-04 05:05:06 補充：

public static void main(String[] args) throws Exception {

BigDecimalOperation decimal = new BigDecimalOperation();

decimal.doOperation();

System.out.println("");

System.out.println("Process completed.");

}

private void out(String s) {

System.out.println(s);

}

}

Source(s): Me
• 5 years ago

所以如果你想婚的念頭已經確定

就去找一家評價好一點的婚友社!

行動吧!

這是我之前參加的婚友社我覺得不錯

或搜尋 紅娘李姐