本帖最後由 b790113g 於 2012-2-25 11:25 編輯
* I2 l2 R% V8 R9 [: Y$ G+ Y1 P9 j/ x& r C5 x
模擬銀行利息公式之計算
+ e4 a4 Q0 S* R$ f9 ?(1) 若將1000元分別存入AB二間銀行,年利為5%,A銀行以複利計算存款,B銀行以單利計算存款,10年後各有多少錢?6 T% E. r' m4 K- h+ H4 p$ U
複利公式:p(1+r)^n: J8 I @; w+ _) `! x! z
單利公式:p(1+n*r) e3 w4 Z5 ]4 B$ c
p:本金 r:利率 n:年限6 s: E) p p! l& O/ d# {# [; n( L, i
(2) 列示出10年中,A、B銀行存款狀況
# }/ _" P- c9 L/ ^1 Q& H% [(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) ;
- }
- //
- }
- }
複製代碼 |