I'm trying to do a Kata on Codewars in Java that asks "you have decided to write a function that will return the first n elements of the sequence with the given common difference step and first element first." Below I have done what is asked, but when I return the final array it returns as two-dimensional (like [[1, 2, 3, 4]] instead of [1, 2, 3, 4]). Please help me understand why and how to fix this!
import java.util.Arrays;
class Progression {
public static String arithmeticSequenceElements(int first, int step,
long total) {
int[] intArr;
intArr = new int [(int)total];
intArr[0] = first;
int i = 1;
while(i<total){
intArr[i] = intArr[i-1] + step;
i++;
}
return Arrays.toString(intArr);
}
}
[]? Because that output isn't possible with the code shown."[[1, 2, 3, 4]]"? I get"[1, 2, 3, 4]".