日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

0330复利计算(修改版)

發布時間:2023/12/15 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 0330复利计算(修改版) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 package kxj; 2 import java.util.Scanner; 3 4 public class Fulijisuan { 5 public static double p,i,f ; 6 public static double n; 7 8 //計算本金 9 public static void Benjin(){ 10 //int n; 11 //float f,i,p; 12 boolean flag; 13 Scanner scanner=new Scanner(System.in); 14 System.out.println("請輸入終值: "); 15 f=scanner.nextDouble(); 16 System.out.println("請輸入年利率: "); 17 i=scanner.nextDouble(); 18 System.out.println("請輸入年數: "); 19 n=scanner.nextInt(); 20 if(n>=0) 21 { 22 if(i>=0&&i<=1) 23 { 24 flag=true; 25 p=(float) (f*1/Math.pow(1+i, n)); 26 } 27 else 28 { 29 System.out.println("輸入的年利率有錯!"); 30 flag=false; 31 32 } 33 } 34 else 35 { 36 System.out.println("輸入的年數有錯!"); 37 flag=false; 38 39 } 40 if(flag) 41 System.out.println("本金為: "+(double)(Math.round(p*100)/100.0)); 42 43 } 44 45 //計算本息和 46 public static void Benxihe(){ 47 double sum1=0,sum2=0; 48 boolean flag; 49 Scanner scanner=new Scanner(System.in); 50 System.out.println("請輸入本金: "); 51 p=scanner.nextDouble(); 52 System.out.println("請輸入年利率: "); 53 i=scanner.nextDouble(); 54 System.out.println("請輸入年數: "); 55 n=scanner.nextInt(); 56 if(n>=0) 57 { 58 if(i>=0&&i<=1) 59 { 60 sum1=(float) (p*Math.pow(1+i, n)); 61 sum2=p*(1+i*n); 62 flag=true; 63 64 } 65 else 66 { 67 System.out.println("輸入的年利率有錯!"); 68 flag=false; 69 70 } 71 } 72 else 73 { 74 System.out.println("輸入的年數有錯!"); 75 flag=false; 76 77 } 78 if(flag) 79 { 80 System.out.println("復利的本息和為: "+(double)(Math.round(sum1*100)/100.0)); 81 System.out.println("單利的本息和為: "+(double)(Math.round(sum2*100)/100.0)); 82 } 83 } 84 85 //計算年數 86 public static void Nianshu(){ 87 boolean flag; 88 Scanner scanner=new Scanner(System.in); 89 System.out.println("請輸入本金: "); 90 p=scanner.nextDouble(); 91 System.out.println("請輸入終值: "); 92 f=scanner.nextDouble(); 93 System.out.println("請輸入年利率: "); 94 i=scanner.nextDouble(); 95 if(i>=0&&i<=1) 96 { 97 n=Logarithm.log(f/p,1+i); 98 flag=true; 99 } 100 else 101 { 102 System.out.println("輸入的年利率有錯!"); 103 flag=false; 104 105 } 106 if(flag) 107 System.out.println("需要存的年數為: "+Math.ceil(n)); 108 } 109 110 //計算年利率 111 public static void Lilv(){ 112 boolean flag; 113 Scanner scanner=new Scanner(System.in); 114 System.out.println("請輸入本金: "); 115 p=scanner.nextDouble(); 116 System.out.println("請輸入終值: "); 117 f=scanner.nextDouble(); 118 System.out.println("請輸入年數: "); 119 n=scanner.nextInt(); 120 if(n>=0) 121 { 122 i=Math.pow(f/p, 1.0/n)-1; 123 flag=true; 124 } 125 else 126 { 127 System.out.println("輸入的年數有錯!"); 128 flag=false; 129 130 } 131 if(flag) 132 System.out.println("年報酬率為: "+(double)(Math.round(i*1000)/1000.0)); 133 } 134 135 //計算本利之和連同年金投資后的總資產 136 public static void Nianjin(){ 137 boolean flag; 138 Scanner scanner=new Scanner(System.in); 139 System.out.println("請輸入每年定投資金: "); 140 p=scanner.nextDouble(); 141 System.out.println("請輸入年利率: "); 142 i=scanner.nextDouble(); 143 System.out.println("請輸入年數: "); 144 n=scanner.nextInt(); 145 if(n>=0) 146 { 147 if(i>=0&&i<=1) 148 { 149 f=p*(1+i)*(Math.pow(1+i,n)-1)/i; 150 flag=true; 151 152 } 153 else 154 { 155 System.out.println("輸入的年利率有錯!"); 156 flag=false; 157 158 } 159 } 160 else 161 { 162 System.out.println("輸入的年數有錯!"); 163 flag=false; 164 165 } 166 if(flag) 167 System.out.println("年資產總值為:"+(double)(Math.round(f*100)/100.0)); 168 } 169 170 //計算每月等額本息還款 171 public static void BenxiHuankuan(){ 172 double f,i,p = 0; 173 int n; 174 boolean flag; 175 Scanner scanner=new Scanner(System.in); 176 System.out.println("請輸入貸款金額: "); 177 f=scanner.nextDouble(); 178 System.out.println("請輸入年利率: "); 179 i=scanner.nextDouble(); 180 System.out.println("請輸入貸款年數: "); 181 n=scanner.nextInt(); 182 if(n>=0) 183 { 184 if(i>=0&&i<=1) 185 { 186 i=i/12; 187 n=n*12; 188 p=f*i*Math.pow(1+i, n)/(Math.pow(1+i, n)-1); 189 flag=true; 190 191 } 192 else 193 { 194 System.out.println("輸入的年利率有錯!"); 195 flag=false; 196 197 } 198 } 199 else 200 { 201 System.out.println("輸入的年數有錯!"); 202 flag=false; 203 204 } 205 if(flag) 206 System.out.println("每月等額本息還款為:"+(double)(Math.round(p*10000)/10000.0)); 207 208 } 209 210 public static void main(String[] args) { 211 int choice; 212 while(true){ 213 System.out.println("\t\t|***********************|"); 214 System.out.println("\t\t| 1. 求 本 金 \t|"); 215 System.out.println("\t\t| 2. 求 本 息 和 \t|"); 216 System.out.println("\t\t| 3. 求 年 數 \t|"); 217 System.out.println("\t\t| 4. 求 利 率 \t|"); 218 System.out.println("\t\t| 5. 求年資產總值\t|"); 219 System.out.println("\t\t| 6. 求等額本息還款\t|"); 220 System.out.println("\t\t| 7. 退 出 \t|"); 221 System.out.println("\t\t|***********************|"); 222 Scanner scanner=new Scanner(System.in); 223 System.out.println("\n請輸入你的選擇(1~7): "); 224 choice=scanner.nextInt(); 225 switch(choice){ 226 case 1: 227 Benjin(); 228 break; 229 case 2: 230 Benxihe(); 231 break; 232 case 3: 233 Nianshu(); 234 break; 235 case 4: 236 Lilv(); 237 break; 238 case 5: 239 Nianjin(); 240 break; 241 case 6: 242 BenxiHuankuan(); 243 break; 244 case 7: 245 System.out.println("Thanks for using!"); 246 System.exit(0); 247 break; 248 default: 249 { 250 System.out.println("輸入有誤!"); 251 break; 252 } 253 } 254 } 255 } 256 }

?

轉載于:https://www.cnblogs.com/950525kxj/p/5339303.html

總結

以上是生活随笔為你收集整理的0330复利计算(修改版)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。