我是二年级计算机科学专业的学生,我刚从第一次面试中回来.
基本上最后我的面试官让我写一个函数,它带有两个参数,一个以磅为单位的数量和一个税率,然后返回一个包含税额的数组.
经过一些试验和错误,我最终写了这样的东西:
public static double[] taxAmount (double pounds, double taxPercentage) {
double taxAmount = pounds * taxPercentage/100;
double[] taxAmountArray = new double[1];
taxAmountArray[0] = taxAmount;
return taxAmountArray;
}
Run Code Online (Sandbox Code Playgroud)
它工作,他似乎很高兴,我想知道为什么我需要为此任务返回一个数组?我觉得问题真的很愚蠢,阵列对这个任务没用了吗?我错过了什么吗?