Given an array of integers, I need to return a new array containing the middle element(s) from the original array. Specifically, the result will have one element if the length o
public int[] makeMiddle(int[] nums) {
if(nums.length>=2){
if(nums[nums.length-1]%2==0) {
int[] arrEven=new int[2];
arrEven[0]=nums[(nums.length/2)-1];
arrEven[1]=nums[(nums.length/2)];
return arrEven;
}
else {
int[] arrOdd=new int[1];
arrOdd[0]=nums[(nums.length/2)];
return arrOdd;
}
}
return nums;
}