Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaBat Array-1 > sameFirstLast

    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

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Well you already failed since Java != JavaScript.

    Hopefully a mod will move it for you.

    What are your error messages?
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    Code:
    public boolean sameFirstLast(int[] nums) {
    if(nums.length>0)
    if(nums[0]==nums[nums.length-1])
    return true;
    return false;
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •