이 기사에서는 복리를 계산하는 방법을 이해할 것입니다. 복리는 다음 공식을 사용하여 계산됩니다 -
Principle*(1+(rate / 100))^time – Principle
복리 이자 − 원금 및 미지급 이자에 부과되는 이율. 이율은 단순이자에 비해 높습니다.
아래는 동일한 데모입니다 -
입력
입력이 -
라고 가정합니다.Enter a Principle number : 100000 Enter Interest rate : 5 Enter a Time period in years : 3
출력
원하는 출력은 -
The Compound Interest is : 15762.50000000001
알고리즘
Step 1 – START Step 2 – Declare four float values principle, rate, time, compound_interest Step 3 – Read values of principle, rate, time, from the user Step 4 – Perform “principle * (Math.pow((1 + rate / 100), time)) – principle” to calculate the compound interest and store it in a simple_interest variable Step 8 – Display compound_interest Step 10 – STOP
예시 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