-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayExercise.java
More file actions
61 lines (55 loc) · 1.54 KB
/
ArrayExercise.java
File metadata and controls
61 lines (55 loc) · 1.54 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
53
54
55
56
57
58
59
60
61
package exercise_array;
import static java.lang.Integer.*;
import static java.lang.String.*;
import static java.lang.System.*;
import static yan_service.YANConstant.*;
import static yan_service.YANService.*;
public class ArrayExercise {
public static void main(String[] args) {
// tit
out.println(BLUE_BOLD);
printlnAdv("Array Exersice");
// content
run();
}
// Fields
private static final int N_MAX = 10;
// Main
private static void run() {
// input
out.println();
var ns = new int[N_MAX];
for (var i = 0; i < N_MAX; i++) {
printAdv(GREEN, format("Nhập số tự nhiên thứ %d: ", i + 1), RESET);
ns[i] = numLimit(0, MAX_VALUE);
}
// output
out.print(YELLOW);
checkMirror(ns);
out.println();
// ctrl
checkOut();
}
// Check mirror
private static void checkMirror(int... args) {
// pick
var isSuccess = false;
var max = args.length;
for (var i = 0; i < max / 2; i++) {
if (args[i] == args[max - 1 - i]) {
isSuccess = true;
printlnAdv(format("Số %d đối xứng ở cặp vị trí %d và %d.", args[i], i + 1, max - i));
}
}
// check back
if (!isSuccess) {
printlnAdv("Không có cặp số đối xứng nào.");
}
}
// Check out
private static void checkOut() {
if (credit() == 1) {
run();
}
}
}