-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNumberArrayImpl.java
More file actions
52 lines (42 loc) · 1.35 KB
/
NumberArrayImpl.java
File metadata and controls
52 lines (42 loc) · 1.35 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
package com.yurii.salimov.lesson03.task05;
import java.util.Arrays;
import java.util.Scanner;
public final class NumberArrayImpl implements NumberArray {
private final Scanner scanner;
private int[] numbers;
public NumberArrayImpl() {
this.scanner = new Scanner(System.in);
}
@Override
public void read() {
final int length = readNumber();
this.numbers = new int[length];
for (int i = 0; i < length; i++) {
this.numbers[i] = readNumber();
}
}
@Override
public void mirror() {
final int length = this.numbers.length;
for (int i = 0; i < (length / 2); i++) {// наприимер a=3; b=4
this.numbers[i] = this.numbers[i] + this.numbers[(length - 1) - i];// a=a+b; (a=7)
this.numbers[(length - 1) - i] = this.numbers[i] - this.numbers[(length - 1) - i];// b=a-b; (b=3)
this.numbers[i] = this.numbers[i] - this.numbers[(length - 1) - i];// a=a-b; (a=4)
}
}
@Override
public void print() {
System.out.println(Arrays.toString(numbers));
}
@Override
public void print(final int index) {
System.out.println(this.numbers[index]);
}
@Override
public int[] get() {
return this.numbers;
}
private int readNumber() {
return this.scanner.nextInt();
}
}