Tech Support Guy banner
Status
Not open for further replies.

If-else statement

667 views 1 reply 2 participants last post by  Cookiegal 
#1 ·
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?
 
Status
Not open for further replies.
You have insufficient privileges to reply here.
Top