本帖最後由 b790113g 於 2012-2-25 11:25 編輯 - G$ X$ n- \4 w- g: D
' O; ^" u8 E+ c, n8 j( p: Y: a$ r0 r模擬銀行利息公式之計算/ A* X t! R! W# U5 i
(1) 若將1000元分別存入AB二間銀行,年利為5%,A銀行以複利計算存款,B銀行以單利計算存款,10年後各有多少錢?' o# f. [# Y: D6 D
複利公式:p(1+r)^n
; `- W: y! k; Y2 u* ~單利公式:p(1+n*r)
6 P) {& Q$ `& U7 N& Kp:本金 r:利率 n:年限
* D2 _2 i+ r* y4 }(2) 列示出10年中,A、B銀行存款狀況
" I1 X! y/ n# c3 m4 p! k% ](3) 存款數目四捨五入至整數- public class jva202{
- public static void main(String arg[]){
- System.out.println("年\tA銀行(複利)\tB銀行(單利)");
- int p = 1000 ;
- double r = 0.05 ;
- int n = 10 ;
- // (int)a 5 (double)b 0.5 (double)a*b = 2.5
- for(int i=1;i<=n;i++){
- int m1 = (int)(p* Math.pow(1+r,i)); //Math.pow 只能帶浮點數
- int m2 = (int)(p*(1+i*r));
- System.out.printf("%d\t%d\t\t%d\n",i,m1,m2) ;
-
- //m1 = (int)(p* Math.pow(1+r,2)); //Math.pow 只能帶浮點數
- //m2 = (int)(p*(1+2*r));
- //System.out.printf("%d\t%d\t%d",2,m1,m2) ;
- }
- //
- }
- }
複製代碼 |