有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在数组中计算工资并返回答案

问题是:

Write a method that takes in an array of salary values and a double rise rate, to calculate and return the array of salaries after they are raised. If, for example, the rise rate is 1.07 and one has the salary of £20000, then after raising the salary is 20000 X 1.07 = 21400.

请注意:这不是一个家庭作业,而是来自软件与技术部的过去考试题;编程1,BikBek,伦敦大学。

到目前为止,我有,但我不认为这是非常正确的,因为编译后,我需要单击inspect

public class salary
{
    public static double [] salary ()
    {
        double [] salary = {20000};
        riseRate = 1.07;
        for (int i = 0; i<salary.length; i++)
        {
            salary [i] = salary[i] * riseRate;
        }
        return salary;
    }
}

共 (1) 个答案

  1. # 1 楼答案

    Write a method that takes in an array of salary values and a double rise rate

    public static void foo(double[] salaries, double riseRate){...}
    

    return the array of salaries after they are raised

    public static double[] foo(double[] salaries, double riseRate){...}
    

    If, for example, the rise rate is 1.07 and one has the salary of £20000, then after raising the salary is 20000 X 1.07 = 21400

    public static double[] foo(double[] salaries, double riseRate){
        for(double salary : salaries){
            salary *= riseRate;
        }  
        return salaries;
    }
    

    构建这个简单方法所需的所有信息都在这里