Advertisement
16112

Compare arrays

Mar 17th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class project {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         int[] nums1 = { 10, 20, 30 };
  7.         int[] nums2 = { 10, 20, 30 };
  8.         if (compareArrays(nums1, nums2)) {
  9.             System.out.println("Equals");
  10.         } else {
  11.             System.out.println("Not equals");
  12.         }
  13.     }
  14.  
  15.     static boolean compareArrays(int[] arr1, int[] arr2) {
  16.         if (arr1.length != arr2.length) {
  17.             return false;
  18.         }
  19.         for (int i = 0; i < arr1.length; i++) {
  20.             if (arr1[i] != arr2[i]) {
  21.                 return false;
  22.             }
  23.         }
  24.         return true;
  25.  
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement