本帖最後由 b790113g 於 2012-2-25 11:25 編輯 2 N6 j3 e: w, J; ^- v x# S7 u/ r1 e
% E% F/ r$ \0 u5 O& B4 ^1 \$ U
模擬銀行利息公式之計算
' g/ Z. ]7 L+ Y4 L( @(1) 若將1000元分別存入AB二間銀行,年利為5%,A銀行以複利計算存款,B銀行以單利計算存款,10年後各有多少錢?
* \! D5 G3 t' v9 }- i複利公式:p(1+r)^n6 @9 i3 n# u& |+ s3 j: j6 M- \8 _
單利公式:p(1+n*r)/ J4 N7 o/ K3 f) o
p:本金 r:利率 n:年限0 x c5 ]) H# o% n0 U# o, c
(2) 列示出10年中,A、B銀行存款狀況
3 g1 I7 N$ U# j8 ?7 w8 R2 J(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) ;
- }
- //
- }
- }
複製代碼 |