Compare whether the two arrays are identical

Source: Internet
Author: User

/* Compare whether the two arrays are identical.
1. Compare whether the length is equal.
2. Check whether the comparison elements are equal.
3. Compare whether the element sequence is equal.
If all values are passed, the two arrays are identical.
*/

Public class testarray {
Public static void main (string [] ARGs ){
Int [] arr1 = new int [] {, 3 };
Int [] arr2 = new int [] {, 3 };
Int m = 0;
Int n = 0;
If (arr1.length! = Arr2.length ){
System. Out. println ("the array length is not equal" + "\ n Array 1:" + arr1.length + "\ n Array 2:" + arr2.length );
Return;
}
For (INT I = 0; I <arr1.length; I ++ ){
M + = arr1 [I];
N + = arr2 [I];
}
If (M! = N ){
System. Out. println ("array elements are different ");
Return;
}
For (INT I = 0; I <arr1.length; I ++ ){
M = arr1 [I];
N = arr2 [I];
If (M! = N ){
System. Out. println ("the order of array elements is not equal" + "\ n not equal index number:" + I );
Return;
}
}
System. Out. println ("Two arrays are identical ");
}
}

// The array content in the instance is manually written, and the computer can generate a random number and then compare it.

Compare whether the two arrays are identical

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.