-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenericArray.java
50 lines (39 loc) · 1.13 KB
/
GenericArray.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/******************************************************************************
Write a Java program to create a generic method that takes two arrays of the same
type and checks if they have the same elements in the same order.
Input:
size of arrays: 4
Java Python
java mark
Java Python
Output:
String 1 and 2: false
String 1 and 3: true
*******************************************************************************/
import java.util.*;
public class Main
{
public static <T> boolean compare(T[] a,T[] b){
for(int i=0;i<a.length;i++){
if(!a[i].equals(b[i])) return false;
}
return true;
}
public static void main(String[] args) {
Scanner x=new Scanner(System.in);
System.out.print("Size of arrays: ");
int n=x.nextInt();
String[] d=new String[n];
String[] e=new String[n];
String[] f=new String[n];
x.nextLine();
for(int j=0;j<n;j++) d[j]=x.next();
x.nextLine();
for(int j=0;j<n;j++) e[j]=x.next();
x.nextLine();
for(int j=0;j<n;j++) f[j]=x.next();
x.nextLine();
System.out.println("String 1 and 2: "+compare(d,e));
System.out.println("String 1 and 3: "+compare(d,f));
}
}