I am 2nd-year computer science student and I just got back from my first ever interview.
Basically at the end my interviewer asked me to write a function that takes two arguments, an amount in pounds and a tax percentage and then return an array with the tax amount.
I eventually wrote something like this after some trial and error:
public static double[] taxAmount (double pounds, double taxPercentage) {
double taxAmount = pounds * taxPercentage/100;
double[] taxAmountArray = new double[1];
taxAmountArray[0] = taxAmount;
return taxAmountArray;
}
It worked and he seemed happy, what I am wondering is why I needed to return an array for this task? I just feel like the question was really stupid the array is useless for this task right?. Am I missing something?
return new double[] { pounds * taxPercentage/100 };