PDA

View Full Version : JavaBat Array-1 > sameFirstLast


brithead
01-29-2009, 02:23 AM
Hey I have to do this hw for comp science ive been working on this problem for quite a while but have 2 errors and dont know how to fix it
The link to my work is

http://javabat.com/prob?id=1189766

and here is the question...
Given an array of ints, return true if the array is length 1 or more, and the first element and the last element are the same.

sameFirstLast({1, 2, 3}) → false
sameFirstLast({1, 2, 3, 1}) → true
sameFirstLast({1, 2, 1}) → true

A1ien51
01-29-2009, 03:48 AM
Well you already failed since Java != JavaScript.

Hopefully a mod will move it for you.

What are your error messages?

BarrMan
01-29-2009, 05:29 PM
public boolean sameFirstLast(int[] nums) {
if(nums.length>0)
if(nums[0]==nums[nums.length-1])
return true;
return false;
}