Two arrays list1 and lis2 are identical if they have the same contents. Write a method that returns true if list1 and li
Posted: Thu May 05, 2022 1:20 pm
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();
}
}
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();
}
}