2014-02-18 32 views
-3

我有這個計算複利的代碼,但我需要它在1年,3年和5年後進行。香港專業教育學院試圖和不能似乎得到它的工作。誰能幫我?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

爲什麼你設置xprincipal *((1+r/12),time),然後設置x=math.pow(5,3)

x現在設置爲math.pow(5,3)並且與您的委託人,費率和時間輸入無關。

另外,您應該指定時間輸入爲年,因爲您已在費率問題中進行硬編碼。

+0

不,不是幾個月而不是幾年,但對於其他正確答案+1。 –

相關問題