-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayChecker.java
More file actions
50 lines (50 loc) · 1.47 KB
/
ArrayChecker.java
File metadata and controls
50 lines (50 loc) · 1.47 KB
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
import java.util.Arrays;
import java.util.Scanner;
public class ArrayChecker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of array: ");
int size = sc.nextInt();
int[] arr = new int[size];
int[] arr1 = new int[size];
System.out.print("Enter the elements of array one with spaces:");
for (int i = 0; i < size; i++) {
arr[i] = sc.nextInt();
}
System.out.print("Enter the elements of array two with spaces:");
for (int i = 0; i < size; i++) {
arr1[i] = sc.nextInt();
}
Arrays.sort(arr);
Arrays.sort(arr1);
int flag=0;
for (int i = 0; i < size; i++) {
if(arr[i] != arr1[i]){
flag++;
break;
}
}
if(flag==0){
System.out.println("The given arrays are equal");
}
else{
System.out.println("The given arrays are not equal");
}
flag =0;
for (int i = 0; i < size; i++) {
for(int j=0;i < size; j++){
if (arr[i] < arr1[j]) {
flag++;
break;
}
}
}
if(flag==0){
System.out.println("The given arrays are compatible");
}
else{
System.out.println("The given arrays are not compatible");
}
sc.close();
}
}