TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
C语言趣味程序百例精解之java实现(14)怎样存钱


程序:
- public class Test14{
- public static void main(String args[]){
- int n1=0,n2=0,n3=0,n5=0,n8=0;
- double term=0,max=0;
- for(int i8=0;i8<3;i8++)
- for(int i5=0;i5<=(20-8*i8)/5;i5++)
- for(int i3=0;i3<=(20-8*i8-5*i5)/3;i3++)
- for(int i2=0;i2<=(20-8*i8-5*i5-3*i3)/2;i2++){
- int i1=20-8*i8-5*i5-3*i3-2*i2;
- term=2000.0*Math.pow((1+0.0063*12),i1)*Math.pow((1+2*0.0066*12),i2)*Math.pow((1+3*0.0069*12),i3)*
- Math.pow((1+5*00075*12),i5)*Math.pow((1+8*0.0084*12),i8);
- if(term>max){
- max=term;n1=i1;n2=i2;n3=i3;n5=i5;n8=i8;
- }
- }
- System.out.printf("存款方式为:");
- System.out.printf("八年存%d次
- ",n8);
- System.out.printf("五年存%d次
- ",n5);
- System.out.printf("三年存%d次
- ",n3);
- System.out.printf("二年存%d次
- ",n2);
- System.out.printf("一年存%d次
- ",n1);
-
- }
- }
- C:at>java Test14
- 存款方式为:八年存0次
- 五年存4次
- 三年存0次
- 二年存0次
- 一年存0次
复制代码
源码下载:http://file.javaxxz.com/2014/11/24/000527640.zip |
|