0
因此,我正在爲這所學校做這個項目,我覺得這很簡單,但我真的很愚蠢。我需要兩種方法;一個只做我想做的計算,另一個用戶輸入數字並顯示計算方法的答案。來自班級網站的樣本可以輕鬆理解如何使用一個用戶輸入的變量,但不是像我需要的那樣;我還需要能夠將它們全部放在一起並在方程中使用它們。這是我到目前爲止:如何在一個方法中使用另一種方法中的變量?
import java.util.*;
import java.text.*;
public class Lab3StarterCodeExperimental {
public static final Scanner CONSOLE = new Scanner(System.in);
public static double compoundInterest(double accountValue) {
double firstCalc = accountValue * 150;
return firstCalc;
}
public static void main(String [] args) {
//print title of lab
System.out.println("Lab 3");
//get user input (present value of account, interest rate, # years, payment per year)
System.out.print("Enter present value of the account: ");
double presentValue = CONSOLE.nextDouble();
System.out.print("Enter the interest rate of the account: ");
double interestRate = CONSOLE.nextDouble();
System.out.print("Enter the number of years: ");
double numOfYears = CONSOLE.nextDouble();
//calculate future value of account
double fvAccount = compoundInterest(presentValue);
//calculate future value of annuity
//print everything
System.out.println("Fake Variable is " + presentValue);
System.out.println("Future value of account is " + fvAccount);
}
}
任何幫助非常感謝!
叫它非常感謝你,這是真棒:) – MPD
不客氣。歡迎來到stackoverflow! – aliteralmind