计算复利的 Java 程序
javaobject oriented programmingprogramming更新于 2024/4/12 8:44:17
在本文中,我们将了解如何计算复利。复利使用以下公式计算 −
Principle*(1+(rate / 100))^time – Principle
复利 − 本金和应计利息所收取的百分比利息。与单利相比,利率更高。
下面是相同的演示 −
输入
假设我们的输入是 −
输入一个原则数字:100000 输入利率:5 输入一个年限:3
输出
所需的输出将是 −
复利为:15762.50000000001
算法
步骤 1 - 开始 步骤 2 - 声明四个浮点值原则、利率、时间、复合利息 步骤 3 -从用户处读取本金、利率、时间的值 步骤 4 – 执行"principle * (Math.pow((1 + rate / 100), time)) –principle"来计算 复利并将其存储在 simple_interest 变量中 步骤 8 – 显示 compound_interest 步骤 10 – 停止
示例 1
import java.util.Scanner;
public class CompoundInterest {
public static void main (String args[]){
double principle, rate, time, compound_interest;
System.out.println("Required packages have been imported");
Scanner my_scanner = new Scanner(System.in);
System.out.println("A Scanner object has been defined ");
System.out.print("Enter a Principle number : ");
principle = my_scanner.nextInt();
System.out.print("Enter Interest rate : ");
rate = my_scanner.nextInt();
System.out.print("Enter a Time period in years : ");
time = my_scanner.nextInt();
compound_interest = principle * (Math.pow((1 + rate / 100), time)) - principle;
System.out.println("The Compound Interest is : " + compound_interest);
}
}
输出
Required packages have been imported A Scanner object has been defined Enter a Principle number : 100000 Enter Interest rate : 5 Enter a Time period in years : 3 The Compound Interest is : 15762.500000000015
示例 2
这里,整数已经被预先定义,并且它的值被访问并显示在控制台上。
public class CompoundInterest{
public static void main (String args[]){
double principle, rate, time, compound_interest;
principle = 100000;
rate = 5;
time = 3;
System.out.printf("The Principle amount is %f \nThe interest rate is %f \nThe time period in years is %f " , principle, rate, time);
compound_interest = principle * (Math.pow((1 + rate / 100), time)) - principle;
System.out.println("\nThe Compound Interest is: " + compound_interest);
}
}
输出
The Principle amount is 100000.000000 The interest rate is 5.000000 The time period in years is 3.000000 The Compound Interest is: 15762.50000000001
相关文章
有用资源
java 参考教程 - 该教程包含有关 java 的更多信息:https://www.cainiaomax.com/java/

