Project: Strictly identical arrays Problem Description: 20 Two arrays are strict
ID: 3706057 • Letter: P
Question
Project: Strictly identical arrays Problem Description: 20 Two arrays are strictly identical if their corresponding elements are equal. Write a program with class name Strictly Identical that prompts the user to enter two lists of integers of size 5 and displays whether the two are strictly identical. Screen Shot 2018-04-12 at 12.17.36 AM Use following method header to pass two arrays and return a Boolean Q Search public static booleane equals(int] arrayl, int array2) Method will return true if arrayl and array2 are strictly identical otherwise it will return false. Here are two sample runs: Sample 1: Enter 5 elements of list1: 23 55 31210 Enter 5 elements of list2: 23 55 31210 Two lists are strictly identical. i Strt a for loop to check the corresponding elements of arrayl and array2. Change variable equal to false if corresponding elements of arrayl 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. Sample 2: Enter 5 elements of list1: 23 55 31210 Enter 5 elements of list2: 23 55 3 210 Two lists are not strictly identical iii)Return equal outside the for loop You can use the following steps in your code: What to deliver? 1 Declare and create two arrays listl and list2 of integer type and size 5 2. Prompt the user to enter 5 elements of listl and list2. Use for loop to read these entries and assign them to the elements of listl and list2 respectively. Example, and lis2. Uise for loop to read these Your java file includir 1. (Code: 5 points, Comments: 2 points) list 1 [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. Your code with other appropriate comments. 2. (3 points) One sample run test the following two lists 12345 and 1 2345 /Method equals 4. Create a method equals outside the main method with the header provided in the problem description. Pass the reference of listl and list2 to the array variables arrayl and array2 respectively inside the method. Inside the method do the followings. i) Create a Boolean variable equal and assign true to it.Explanation / Answer
IdenticalArrrays.java
import java.util.Scanner;
public class IdenticalArrrays {
public static void main(String[] args) {
Scanner scan= new Scanner(System.in);
int array1[] = new int[5];
int array2[] = new int[5];
System.out.println("Enter 5 elements of list1: ");
for(int i=0;i<5;i++) {
array1[i]=scan.nextInt();
}
System.out.println("Enter 5 elements of list2: ");
for(int i=0;i<5;i++) {
array2[i]=scan.nextInt();
}
boolean equals = true;
for(int i=0;i<5;i++) {
if(array1[i]!=array2[i]) {
equals=false;
break;
}
}
if(equals) {
System.out.println("Two lists are strictly identical");
} else {
System.out.println("Two lists are not strictly identical");
}
}
}
Output:
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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.