// compareArrays() هنا قمنا بتعريف الدالة
public static void compareArrays(int[] arr1, int[] arr2) {
if (arr1.length == arr2.length)
System.out.print("They have the same length");
System.out.println("They have different length");
for (int i = 0; i < arr1.length; i++)
System.out.println(" but their values are not equals");
System.out.println(" and their values are equal");
// compareArrays() هنا قمنا بإنشاء 4 مصفوفات أحادية و من مقارنتهم بواسطة الدالة
public static void main(String[] args) {
int[] arr1 = {1, 2, 3, 4, 5};
int[] arr2 = {1, 2, 3, 4, 5};
int[] arr3 = {1, 2, 3, 6, 8};
int[] arr4 = {1, 2, 3, 4};
System.out.print("Compare arr1 & arr2 => ");
compareArrays(arr1, arr2);
System.out.print("Compare arr2 & arr3 => ");
compareArrays(arr2, arr3);
System.out.print("Compare arr3 & arr4 => ");
compareArrays(arr3, arr4);
public class Main {
// compareArrays() هنا قمنا بتعريف الدالة
public static void compareArrays(int[] arr1, int[] arr2) {
if (arr1.length == arr2.length)
{
System.out.print("They have the same length");
}
else
{
System.out.println("They have different length");
return;
}
for (int i = 0; i < arr1.length; i++)
{
if (arr1[i] != arr2[i])
{
System.out.println(" but their values are not equals");
return;
}
}
System.out.println(" and their values are equal");
}
// compareArrays() هنا قمنا بإنشاء 4 مصفوفات أحادية و من مقارنتهم بواسطة الدالة
public static void main(String[] args) {
int[] arr1 = {1, 2, 3, 4, 5};
int[] arr2 = {1, 2, 3, 4, 5};
int[] arr3 = {1, 2, 3, 6, 8};
int[] arr4 = {1, 2, 3, 4};
System.out.print("Compare arr1 & arr2 => ");
compareArrays(arr1, arr2);
System.out.print("Compare arr2 & arr3 => ");
compareArrays(arr2, arr3);
System.out.print("Compare arr3 & arr4 => ");
compareArrays(arr3, arr4);
}
}