If-else statement

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

BellRaskolnikov

Thread Starter
Joined
Oct 26, 2012
Messages
5
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?
 

Cookiegal

Karen
Administrator
Malware Specialist Coordinator
Joined
Aug 27, 2003
Messages
117,908
Sorry but we don't help with homework here. You need to do the studying and research the answer on your own if you want to learn properly.

Closing thread.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top