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;
    }
}

Answers


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.

or

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

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

Using std::function for memberfunctions

c++ c++11 c++-standard-library std-function member-functions

My question is about using std::function to class methods. Suppose I have the following class hierarchy:

Java socket output stream

java sockets networking

Can you have an PrintWriter and ObjectOutputStream on the same sockets output stream?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.