Question: Two arrays are strictly identical if their corresponding elements are equal. Write a program with class name StrictlyIdentical that prompts the user to enter two
Two arrays are strictly identical if their corresponding elements are equal. Write a program with class name StrictlyIdentical that prompts the user to enter two lists of integers of size 5 and displays whether the two are strictly identical. Use following method header to pass two arrays and return a Boolean. public static boolean equals(int[] array1, int[] array2) Method will return true if array1 and array2 are strictly identical otherwise it will return false. Here are two sample runs: Sample 1: Enter 5 elements of list1: 23 55 31 2 10 Enter 5 elements of list2: 23 55 31 2 10 Two lists are strictly identical. Sample 2: Enter 5 elements of list1: 23 55 31 2 10 Enter 5 elements of list2: 23 55 3 2 10 Two lists are not strictly identical. You can use the following steps in your code:
1. Declare and create two arrays list1 and list2 of integer type and size 5. 2. Prompt the user to enter 5 elements of list1 and list2. Use for loop to read these entries and assign them to the elements of list1 and list2 respectively. Example, list1[i] = input.nextInt(); 3. Invoke a boolean method equals to pass the two arrays. If the return type is true then display that the lists are strictly identical otherwise, display that lists are not strictly identical. //Method equals 4. Create a method equals outside the main method with the header provided in the problem description. Pass the reference of list1 and list2 to the array variables array1 and array2 respectively inside the method. Inside the method do the followings. i) Create a Boolean variable equal and assign true to it.
ii) Start a for loop to check the corresponding elements of array1 and array2. Change variable equal to false if corresponding elements of array1 and array2 are not identical. For loop will iterate as long as the index is less than the length of the arrays and Boolean variable equal is true. iii) Return equal outside the for loop. What to deliver? Your .java file including: 1. (Code: 5 points, Comments: 2 points) Your code with other appropriate comments. 2. (3 points) One sample run test the following two lists: 1 2 3 4 5 and 1 2 3 4 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
