好吧,我似乎無法通過乘以inputP * inputR來找到我的興趣,假設這是因爲即使在使用此方法後,我的scanner變量inputR和inputP仍未轉換爲雙變量:System.out.println(inputR。 nextDouble()); - 問題是什麼?爲什麼我的Scanner變量不能轉換爲雙精度型:System.out.println(inputR.nextDouble());?
import java.util.Scanner;
public class test {
//This program will display the value of the principle for each of the next 5 years
public static void main(String[] args) {
Scanner inputR = new Scanner(System.in); Scanner inputP = new Scanner(System.in);
double years = 0;
System.out.println("Please enter the principle value for year one: ");
System.out.println(inputP.nextDouble());
System.out.println("Please enter the interest rate for year one: ");
System.out.println(inputR.nextDouble());
while (years < 5) {
double interest;
years = years + 1;
interest = inputP * inputR;
principle = inputP + interest;
System.out.println("Your principle after 5 years is: " + principle);
}
}
}
您正試圖乘以2臺掃描儀。這是不會做得很好的..嘗試將你從掃描儀獲得的輸入存儲在雙變量中,並使這些變量多樣化。 –