-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestEx.java
More file actions
34 lines (29 loc) · 838 Bytes
/
TestEx.java
File metadata and controls
34 lines (29 loc) · 838 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
31
32
33
34
package lesson7;
import java.util.Arrays;
public class TestEx {
public int[] task1(int[] data) {
for (int i = data.length - 1; i >= 0; i--) {
if (data[i] == 4) {
return Arrays.copyOfRange(data, i + 1, data.length);
}
}
throw new RuntimeException("Invalid array");
}
public boolean task2(int[] data) {
boolean contains1 = false;
boolean contains2 = false;
for (int i = 0; i < data.length; i++) {
switch (data[i]) {
case 1:
contains1 = true;
break;
case 4:
contains2 = true;
break;
default:
return false;
}
}
return contains1 && contains2;
}
}