我不確定如何去做這個計算。直到我試圖獲得投資額時,我才把所有的東西都拿下來。我知道我現在所擁有的是錯誤的,但谷歌對我來說並不是很有幫助,而我的書就沒有我需要的東西來完成這件事。我如何計算一大堆不同的掃描儀輸入?
這裏是我現在所擁有的
import java.util.Scanner;
class InvestmentCalculator {
public static void main(String[] args) {
// create a scanner object
Scanner input = new Scanner(System.in);
// Prompt user to enter investment amount
Scanner amount = new Scanner(System.in);
System.out.println("Enter Investment Amount");
while (!amount.hasNextDouble()) {
System.out.println("Only Integers");
amount.next();
}
//Promt user to enter interest rate
Scanner interest = new Scanner(System.in);
System.out.println("Enter Interest Percentage in decimals");
while (!interest.hasNextDouble()) {
System.out.println("Just like before, just numbers");
interest.next();
}
//Prompt user to enter number of years
Scanner years = new Scanner(System.in);
System.out.println("Enter Number of Years");
while (!years.hasNextDouble()) {
System.out.println("Now you are just being silly. Only Numbers allowed");
years.next();
}
//Compute Investment Amount
double future = amount * Math.pow((1 + interest), (years * 12));
//Display Results
System.out.println("Your future investment amount is " + future);
}
}
任何援助將是非常非常有幫助!
你的計算仍然是錯誤的......和我沒有說,2小時前:P – MadProgrammer
@MadProgrammer - 「你的代碼應該是這樣的「 - 我沒有說」這是你的代碼「.. – TheLostMind
我沒有說代碼是,但我很確定我說OP沒有必要使用不同的掃描儀,而且一個就足夠了;) – MadProgrammer