-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem5.java
More file actions
30 lines (25 loc) · 940 Bytes
/
Problem5.java
File metadata and controls
30 lines (25 loc) · 940 Bytes
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
/*Write the Java method below that takes two integer arrays A and B and returns true only if the
values in A appear consecutively in B. You may assume all values in A are distinct. However, the values in B
may or may not include duplicates. */
public class Problem5 {
public static void main(String[] args) {
int[] A = {55, 33, 22};
int[] B = {7, 6, 55, 33, 5, 22, 1};
System.out.println(appearsConsecutively(A, B));
} //end of main method
public static boolean appearsConsecutively(int[] A, int[] B) {
String arrayA = "";
String arrayB = "";
for (int i = 0; i < A.length; i++) {
arrayA += A[i];
}
for (int i = 0; i < B.length; i++) {
arrayB += B[i];
}
if (arrayB.contains(arrayA)) {
return true;
} else {
return false;
}
} // end of appearsConsecutively
}//end of class