2014-02-18 5 views
-3

복리이자를 계산하는이 코드가 있지만 1, 3, 5 년 후에는이 코드가 필요합니다. ive 시도하고 그것을 작동시키지 못할 것. 누구든지 나를 도울 수 있습니까?1, 3 및 5 년 후 복리이자

import java.util.Scanner; 

public class CompoundInterest { 

public static void main(String[] args) { 
Scanner input = new Scanner(System.in); 

double principal = 0; 
double rate = 0; 
double time = 0; 

double x = 0; 

System.out.print("Enter the amount invested : "); 
principal = input.nextDouble(); 

System.out.print("Enter the Rate of interest : "); 
rate = input.nextDouble(); 

System.out.print("Enter the Time of loan : "); 
time = input.nextDouble(); 


x = principal * Math.pow((1 + rate/12),time); 
x = Math.pow(5,3); 

System.out.println(""); 
System.out.println("The Compound Interest after 1 year is : " 
+ x); 

} 

} 
+0

http://qrc.depaul.edu/studyguide2009/notes/savings%20accounts/compound%20interest.htm – OldProgrammer

답변

2

왜 다음, principal *((1+r/12),time)x을 설정 x=math.pow(5,3)을 설정합니까?

x은 이제 math.pow(5,3)으로 설정되며 귀하의 원금, 요율 및 시간 입력 내용과 아무 관계가 없습니다.

또한 요율 질문에 하드 코딩 된대로 입력 시간을 연도로 지정해야합니다.

+0

아니요, 아니요, 몇 달이 아니라 몇 년이 지나면 작동합니다. 그렇지 않으면 정답입니다. –