Advertisement
petarBenov16118

Compare arrays

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