Can't return the answer

The answer should be returned but it does not display for some reason. I have printed within for loop and seen that it's correct answer.

public class Salary
    public static void main (String[]args)
        double [] salary = {20000.00};
        double riseRate = 1.07;

        calculateSalary(salary, riseRate);
    public static double [] calculateSalary(double [] salary, double riseRate)
        for (int i=0; i<salary.length; i++)
            salary [i] = salary [i] * riseRate;
        return salary;


You are returning an array. The salary is in the the first position of you array. If you want to see the salary you would need to use

return salary[0];

in your method.



in the main.

What you're trying to print right now is the actual array, not a value.

I am not sure why you are doing it like this, though. Why not just use a double instead of double[]?

That's because you're not printing out the answer. Add a print statement in main.

System.out.println(calculateSalary(salary, riseRate)[0]);

Need Your Help

Python; for loop; iterating over an existing variable set

python variables for-loop iteration pythonanywhere

Suppose I have a set of variables which are already created. They use a similar (i.e. predictable naming convention). Example: