programming-examples/java/Basics/Check The Equality Of Two Arrays In Java.java
2019-11-18 14:44:36 +01:00

27 lines
670 B
Java

public class EqualityOfTwoArrays {
public static void main(String[] args) {
int[] arrayOne = {
2, 5, 1, 7, 4
}
;
int[] arrayTwo = {
2, 5, 1, 7, 4
}
;
boolean equalOrNot = true;
if(arrayOne.length == arrayTwo.length) {
for (int i = 0; i < arrayOne.length; i++) {
if(arrayOne[i] != arrayTwo[i]) {
equalOrNot = false;
}
}
} else {
equalOrNot = false;
}
if (equalOrNot) {
System.out.println("Two Arrays Are Equal");
} else {
System.out.println("Two Arrays Are Not equal");
}
}
}