-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDropNumber.java
More file actions
36 lines (29 loc) · 908 Bytes
/
DropNumber.java
File metadata and controls
36 lines (29 loc) · 908 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
35
36
/
class dropNum {
public static void main(String[] args) {
System.out.println("");
System.out.println("1 3 4");
System.out.println("");
System.out.println("8 8 4");
System.out.println("");
int[] values = {8, 8, 1, 3, 4};
int[] middle = dropNumber(values, 3);
int[] out = dropNumber(middle, 1);
for (int value : out) {
System.out.print("" + value + " ");
}
}
public static int[] dropNumber(int[] input, int pos) {
if (input.length == 0 || pos >= input.length) {
throw new IllegalArgumentException();
}
int[] result = new int[input.length - 1];
for (int i = 0; i < pos; i++) {
result[i] = input[i];
}
for (int i = pos; i + 1 < input.length; i++) {
result[i] = input[i + 1];
}
return result;
}
}