I want to compare the element of two arrays, here is my code:
public class twoarrs {
boolean arrays(int[] arr1, int[] arr2){
for (int i = 0; i <= arr1.length - 1; i++){
for (int j = 0; j <= arr2.length - 1; j++){
if (arr1[i] < arr2[j]){
System.out.println("this is true");
}
else{
System.out.println("this is false");
}
}
}
return true;
}
public static void main(String[] args){
twoarrs compare = new twoarrs();
int[] a1 = {4,5};
int[] a2 = {1,200};
compare.arrays(a1, a2);
}
}
This code will print four results on the screen(for now they are false, true, false, true), how can I return a true value if all the elements in a1 are smaller than the elements in a2? Means I want to return a value after all the for loops are executed.
And why the result will be all false if I add the code which were hidden?
Any help? Thank you.