Pages

Wednesday, October 29, 2025

Self-practice-01: Check if arrays are matching or not in Java

 import java.util.*;


public class Main

{

    

    

    public static void ifMatch(int[] arr) {

        

        // Combine array with a predefined array

        int[] pattern = {4, 3, 2, 6};

        

        // Check if arrays have same length

        if(Arrays.equals(arr, pattern)) {

            System.out.println("Yes, Array is matching.");

        } else {

            System.out.println("No, Array isn't matching.");

        }

    }

    

    

    

public static void main(String[] args) {

int[] testArr = {4, 3, 2, 6};

System.out.print("Array 1: ");

ifMatch(testArr);

int[] testArr2 = {4, 3, 2, 9};

System.out.print("Array 2: ");

ifMatch(testArr2);

}

}

No comments:

Post a Comment

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...