-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion134_InnerAndOuter.java
More file actions
63 lines (49 loc) · 1.52 KB
/
Question134_InnerAndOuter.java
File metadata and controls
63 lines (49 loc) · 1.52 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
51
52
53
54
55
56
57
58
59
60
61
62
63
package week7_Array_2D_ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Question134_InnerAndOuter {
public static void main(String[] args) {
// olcay // Jul 24, 2020
/*Given two arrays of ints sorted in increasing order, outer and inner, print out true if all of the numbers in inner appear in outer. Take advantage of the fact that both arrays are already in sorted order.
Example:
input (outer): 1, 2, 4, 6
input (inner): 2, 4
output: true
Example:
input (outer): 1, 2, 4
input (inner): 6, 5
output: false*/
Scanner scan = new Scanner(System.in);
System.out.println("Write size of the inner : ");
int sizeInner = scan.nextInt();
System.out.println("Write size of the Outer : ");
int sizeOuter = scan.nextInt();
int[] inner = new int[sizeInner];
int[] outer = new int[sizeOuter];
for(int i =0; i < sizeInner; i++) {
System.out.println("Write the number " + (i+1) + " of the Inner");
inner[i] = scan.nextInt();
}
for(int j =0; j < sizeOuter; j++) {
System.out.println("Write the number " + (j+1) + " of the Outer");
outer[j] = scan.nextInt();
}
Arrays.sort(inner);
Arrays.sort(outer);
//WRITE YOUR CODE HERE
int count=0;
for(int i=0;i<sizeInner; i++) {
for(int j=0; j<sizeOuter;j++) {
if(inner[i]==outer[j]) {
count++;
break;
}
}
}
if(count==sizeInner) {
System.out.println(true);
}else {
System.out.println(false);
}
}
}