The code given below checks if two integer arrays are the same or not.
public class equal {
public static void main(String[] args)
{
// Initialize the first array
int a[] = { 10, 30, 11 };
// Initialize the second array
int b[] = { 10, 30, 12 };
int flag = 1;
// Check if the elements are same or not
if (a.length == b.length) {
for (int i = 0; i < a.length; i = i + 1) {
if (a[i] != b[i]) {
flag=0;
break; //if the elements are different, set flag as 0 and break out of the loop
}
}
}
else {
flag = 0;
}
if (flag==1) {
System.out.println("Arrays are equal");
}
else {
System.out.println("Arrays are not equal");
}
}
}
OUTPUT:
Arrays are not equal
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
The code given below checks if two integer arrays are the same or not.