I need help in finding out how to get the Fvalue1 from method1 and return it to the main method.
import java.util.*;
public class FutureValues {
public static void main(String[] args) {
Scanner CONSOLE = new Scanner(System.in);
System.out.print("present value : ");
double Pvalue = CONSOLE.nextDouble();
System.out.print("interest rate : ");
double Interest = CONSOLE.nextDouble();
System.out.print("number of years : ");
double Years = CONSOLE.nextDouble();
method1(Pvalue, Interest, Years);
System.out.print("The future value using compound interest = " + Fvalue1);
return Fvalue1;
}
public static double method1(double Pvalue, double Interest, double Years) {
return Fvalue1 = Pvalue * Math.pow(1 + Interest / 100, Years);
}
}
You are returning the answer incorrectly, and not setting it in the calling function. This should work:
Key changes being:
and