Question: Write a method that detects if two integer arrays contain the same elements, but not necessarily in the same order: sameElts( int[], int[] ) method.

Write a method that detects if two integer arrays contain the same elements, but not necessarily in the same order: sameElts( int[], int[] ) method.

The method should must not change the arrays it is given as parameters. The position of elements in the array might be crucial to an application. In general, methods should must avoid side effects. So imain() (below) the two arrays should will not change.

class ArraySameElements { public static boolean sameElts( int[] a, int[] b ) { // ============ INSERT CODE HERE ============ } public static void main ( String[] args ) { int[] arrayA = { 1, 2, 3, 4, 2 }; int[] arrayB = { 4, 2, 3, 2, 1 }; if ( sameElts( arrayE, null ) ) System.out.println( "Same Elements" ); else System.out.println( "DIFFERENT elements" ); } } 

Assume that the two arrays have elements in a limited range, perhaps zero to one hundred. Declare two local arrays indexed zero to one hundred that count how many of each value is in each array.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!