Push 1 Push 1 - 3 months ago 20
Java Question

Java not returning value

If I could get a explanation of the issue and the proper code, I would really appreciate it.

public class functiond {

public static double itemCount = 1.99;
public static double dollarsProvided = 2.00;

public static double makeChange(double itemCount, double dollarsProvided) {
double change = dollarsProvided - itemCount;
return change;
}
public static double main(String[] args) {
makeChange(1.99, 2.00);
}
}


Just want it to print out "change".

Answer

Your function is returning value but you are not printing it.

As you are declaring itemCount and dollarsProvided globally you don't need to pass them as parameter.

public class functiond {

    public static double itemCount = 1.99;
    public static double dollarsProvided = 2.00;

    public static double makeChange() {
        double change = dollarsProvided - itemCount;
        return change;
    }
    public static void main(String[] args) {
        System.out.println(makeChange());
    }
}