「本金问题java」本金和利息问题

博主:adminadmin 2022-11-30 04:32:06 72

今天给各位分享本金问题java的知识,其中也会对本金和利息问题进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java问题求解答 本金1000元 年利率0.05 每年都存进2000元,要多少年才能有一百万?

public static void main(String[] args) {

double number=1000;//本金

for (int i = 0; i 1000000; i++) {//用这种极端算法。假设需要100万年才可以获得100万

number+=number*0.05+2000;//每年本金加利息再加上每年多存2000元作为下一年的本金算

if(number=1000000){//当本金大于或等于一百万的时候输出年份和数目

System.out.println(i);//要多少年

System.out.println(number);//有多少钱

break;//退出循环

}

}

}

用JAVA编写一个输入和存入本金的程序怎么写

import java.util.*;

public class Test2 {

public static void main(String[] args) {

Scanner scan=new Scanner(System.in);

System.out.println("输入本金");

int a=scan.nextInt();//输入本金

double firstInterest=0.0225*a*1;

double secondInterest=0.027*a*2;

double thirdInterest=0.0324*a*3;

double fifthInterest=0.036*a*5;

System.out.println("一年的利息"+firstInterest);

System.out.println("两年的利息"+secondInterest);

System.out.println("三年的利息"+thirdInterest);

System.out.println("五年的利息"+fifthInterest);

}

}

用java写代码,将钱存入银行假设年利率一直保持为3.25%每过1年将本金和利息相加作为新的本金。

第1年末:10000+10000*0.0325

第2年末:(10000+10000*0.0325+10000) + (10000+10000*0.0325+10000)*0.0325

。。。。。。。。。。。。。。。。。。。。。。

在java里怎么做 存入1000本金,计算一年,二年,三年,五年,到期取款时,银行应支付的本息是多少

public class Test2 {

public static void main(String[] args) {

float i = 1000;

int j = 0;

if (args.length 1){

System.out.println("参数个数不正确");

System.exit(-1);

}

try{

j = Integer.parseInt(args[0]);

if(j 0){

System.out.println("请输入大于0的年限");

System.exit(-1);

}

if(j 4){

System.out.println("请输入5以下的年限");

System.exit(-1);

}

}catch (NumberFormatException e){

System.out.println("输入了非法数字");

}

switch(j){

case 1: i=(float) (i*(1+0.0225));break;

case 2: i=(float) (i*(1+0.027));break;

case 3: i=(float) (i*(1+0.0324));break;

case 4: i=(float) (i*(1+0.036));break;

}

System.out.print(i);

}

}

便已成功后通过运行java Test1 后面空格接一个年限参数 比如java Tes1 4 计算出四年的本息!

关于本金问题java和本金和利息问题的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-11-30,除非注明,否则均为首码项目网原创文章,转载请注明出处。