Given Problem: Given an array of ints, return true if 6 appears as either the first or last element in the array. The array will be length 1 or more.
My Answer:
public boolean firstLast6(int[] nums) {
for(int i = 0; i < nums.length - 1; i++){
if ( nums[0]== 6 || nums[nums.length - 1]== 6){
return true;
else
return false;}
}
This somehow return an error and it seemingly inside the if-else loop. What am i doing wrong?
My Answer:
public boolean firstLast6(int[] nums) {
for(int i = 0; i < nums.length - 1; i++){
if ( nums[0]== 6 || nums[nums.length - 1]== 6){
return true;
else
return false;}
}
This somehow return an error and it seemingly inside the if-else loop. What am i doing wrong?