Java - Basic use of arrays

Posted by javaisjusttoohard on Stack Overflow See other posts from Stack Overflow or by javaisjusttoohard
Published on 2012-11-16T04:48:50Z Indexed on 2012/11/16 5:00 UTC
Read the original article Hit count: 63

Filed under:

This is a basic question but I do need some help.

Given two arrays of ints, a and b, return true if they have the same first element or they have the same last element. Both arrays will be length 1 or more.

commonEnd({1, 2, 3}, {7, 3}) ? true

commonEnd({1, 2, 3}, {7, 3, 2}) ? false

commonEnd({1, 2, 3}, {1, 3}) ? true

I have the following code but it wont compile:

public boolean commonEnd(int[] a, int[] b) {
    if(a[0] == b[0] || a[a.length-1] ==b[b.length-1])
        return true;
}

© Stack Overflow or respective owner

Related posts about java