I've been trying at this for the entire day. I have an assignment and basically I need to check if 2 arrays have the same elements (w/o having the same order. My idea is
1- check if theyre the same length. if not then theyre obviously not the same
2- to read one element in array 1 and then look for it in the other array, then increment a counter and at the end check if the counter is equal to the length of the array.
i'm getting this error: missing return statement
i need to say that i'm not allowed to use things like sort or hash to solve this since i've seen methods with these before but they cant help here.
public static boolean isSame(int[] ArrayX,int [] ArrayY){
int count=0;
if(ArrayX.length!=ArrayY.length)// to check that they have the same size
return false;
for (int i=0;i<ArrayX.length;i++){
for(int j=0;j<ArrayY.length;j++)//this loop is to search for element[i] in array Y
{
if (ArrayY[j]==ArrayX[i])
count++;
}
}
if (count==ArrayX.length) //to check that number of identical elements is equal to the size
return true;
}