我有一個問題,輸出應該是雙重的,但它是字符串 我想添加兩個double值,但它將它作爲一個字符串。我正在使用eclipse。目前該程序正在編譯和運行。如果有人有片刻我會很感激。乾杯。這是源代碼。double + double = String?
import java.util.Scanner;
public class FutureInvestment
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter investment amount: ");
double investmentAmount = input.nextDouble();
System.out.println("Enter monthly interest rate: ");
double monthlyInterestRate = input.nextDouble();
System.out.println("Enter number of years: ");
int numberOfYears = input.nextInt();
double futureInterestValue = investmentAmount * (Math.pow((1 + monthlyInterestRate), numberOfYears * 12));
System.out.println("Accumulated value is: " + futureInterestValue + investmentAmount);
}
}
這裏的輸出我得到進入投資金額:輸入月息: 4.25 輸入的年數:累計值是:4.384414858452464E111000.0 – Kiril 2012-02-26 15:55:01
和預期結果的累計值1043.34 – Kiril 2012-02-26 15:55:19
我想我的回答可以幫助你 – 2012-02-26 16:07:25