I'm new to Java and am using codingbat to practice. One of the problems is
"Given an array of ints length 3, figure out which is larger, the first or last element in the array, and set all the other elements to be that value. Return the changed array."
I'm geting the error in the title. Why is this? Thanks
public int[] maxEnd3(int[] nums) {
if (nums[0] > nums[2]){
return new int [3] = {nums[0], nums[0], nums[0]};
}
else if (nums[2] > nums[0]){
return new int[3] = {nums[2], nums[2], nums[2]};
}
return nums;
}
Aucun commentaire:
Enregistrer un commentaire