-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask6_7.java
More file actions
24 lines (20 loc) · 768 Bytes
/
Task6_7.java
File metadata and controls
24 lines (20 loc) · 768 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
import java.util.Arrays;
import static utils.LineSeparator.*;
public class Task6_7 {
public static void main(String[] args) {
int[] digits = new int[args.length];
for (int i = 0; i < args.length; i++) {
digits[i] = Integer.parseInt(args[i]);
}
System.out.print("Your Digits: " + Arrays.toString(digits) + ";" + lineSeparator());
System.out.println("Result Elements that are equal to half the sum of neighboring elements: ");
counter(digits);
}
private static void counter(int[] array) {
for (int i = 0; i < array.length - 2; i++) {
if (array[i + 1] == (array[i] + array[i + 2]) / 2) {
System.out.print(" " + array[i + 1]);
}
}
}
}