Two arrays list1 and lis2 are identical if they have the same contents. Write a method that returns true if list1 and li

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Two arrays list1 and lis2 are identical if they have the same contents. Write a method that returns true if list1 and li

Post by answerhappygod »

Two arrays list1 and lis2 are identical if they have the same
contents. Write a method that returns true if list1 and list2 are
identical, false, otherwise. public static boolean identical(int[]
list1, int[] list2)
Sample runs
Input 1:
Output 1:
Input 2:
Output 2:
Given Code:
import java.util.Scanner;
public class Test {
public static boolean identical(int[] list1, int[]
list2) {
// your code starts here
// your code ends here
}
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
int[] list1, list2;
//Enter the size of first array
int n = stdin.nextInt();
list1 = new int[n];
//Enter the first array
for (int i = 0; i < n; i++)
list1 = stdin.nextInt();
//Enter the size of second array
int m = stdin.nextInt();
list2 = new int[m];
//Enter the second array
for (int i = 0; i < m; i++)
list2 = stdin.nextInt();
if (identical(list1, list2)) {
System.out.println("Two lists are
identical");
} else {
System.out.println("Two lists are
not identical");
}
stdin.close();
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply