java计算五年本金利息的简单介绍

博主:adminadmin 2023-03-19 22:53:08 372

本篇文章给大家谈谈java计算五年本金利息,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

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

package com.sh.lw;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class CalculationOfPrincipalAndInterest {

private static final int PRINCIPAL = 1000;

/**

* 主函数 (第一个参数是年,第二个参数是利率)

* @param args

*/

public static void main(String[] args) {

CalculationOfPrincipalAndInterest copai = new CalculationOfPrincipalAndInterest();

try {

if(!copai.isLegal(args))

return;

else{

}

Integer year = new Integer(args[0].trim());

Float interest = new Float(args[1].trim());

Float result = copai.countPrincipalAndInterest(year, interest);

copai.printResult(result);

} catch (Exception e) {

// TODO Auto-generated catch block

System.out.println(e.getMessage());

}

}

/**

* 判断输入是否合法

*/

public boolean isLegal(String[] arr) throws Exception

{

if(arr.length2)

throw new Exception("只需要两个参数!");

if(arr.length2)

throw new Exception("请输入参数!");

Pattern p = Pattern.compile("\\d+");

Matcher m = p.matcher(arr[0]);

Matcher m2 = p.matcher(arr[1]);

boolean b = m.matches();

boolean b1 = m2.matches();

if(bb1)

return true;

return false;

}

/**

* 计算本息

*/

public Float countPrincipalAndInterest(Integer year,Float interest)

{

/*利息和*/

Float sumInterest = CalculationOfPrincipalAndInterest.PRINCIPAL*year*interest;

/*本息*/

Float result = sumInterest + CalculationOfPrincipalAndInterest.PRINCIPAL;

return result;

}

/**

* 输出结果

*/

public void printResult(Float f)

{

System.out.println("*****************************");

System.out.println("输出结果为:"+f+"元");

System.out.println("*****************************");

}

}

在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编写程序:求银行本息的!题目如下:

简单些了个,如果没理解错的话,应该可以满足要求:

public class Benxi{

private double benxi;//本息

private double lilu;//年利率

//计算本息

private double resBenxi(double money,int year){

benxi=money+money*getLilu(year)*year;

return benxi;

}

//选择利率

private double getLilu(int year){

switch(year){

case 1:

lilu=2.25/100;

break;

case 2:

lilu=2.7/100;

break;

case 3:

lilu=3.24/100;

break;

case 5:

lilu=3.6/100;

break;

}

return lilu;

}

public static void main(String[] args){

Benxi bx=new Benxi();

System.out.println("10000元存一年的本息为:"+bx.resBenxi(10000,1));

System.out.println("10000元存两年的本息为:"+bx.resBenxi(10000,2));

System.out.println("10000元存三年的本息为:"+bx.resBenxi(10000,3));

System.out.println("10000元存五年的本息为:"+bx.resBenxi(10000,5));

}

}

Java 作业:在银行存款 每年的利率为0.003,计算出5年后获得本金 代码怎能打?

public class getMoney {

public double getEachYearMoney(double money){

return getEachYearMoney(money)*1.0003;

}

public void getFiveYearMoney(){

double summoney=0;

double money = 10000;

for(int i =0;i5;i++){

summoney=getEachYearMoney(summoney);

}

}

}

用JAVA怎么写

public static void main(String[] args) {

BigDecimal initMoney = new BigDecimal("20000.0");

BigDecimal liXi = new BigDecimal("0.05");

BigDecimal result=new BigDecimal("0");

for(int i=0;i=20;){

i+=5;

result=liXi.multiply(initMoney).add(initMoney);

initMoney=liXi.multiply(initMoney).add(initMoney);

liXi=liXi.add(new BigDecimal("0.05"));

}

System.out.println(result.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());

}

java计算五年本金利息的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、java计算五年本金利息的信息别忘了在本站进行查找喔。