-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfExercise1.java
More file actions
73 lines (65 loc) · 1.88 KB
/
IfExercise1.java
File metadata and controls
73 lines (65 loc) · 1.88 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
62
63
64
65
66
67
68
69
70
71
72
73
package exercise_if;
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 IfExercise1 {
public static void main(String[] args) {
// tit
out.println(BLUE_BOLD);
printlnAdv("If Exersice 1");
// content
run();
}
// Fields
private static final int N_MAX = 3;
// 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
printlnAdv(YELLOW, format("Kết luận: %s.", checkOrder(ns)));
out.println();
// ctrl
checkOut();
}
// Check ascending
private static boolean isAscending(int... args) {
var isSuccess = true;
for (var i = 0; i < args.length - 1; i++) {
if (args[i] > args[i + 1]) {
isSuccess = false;
break;
}
}
return isSuccess;
}
// Check descending
private static boolean isDescending(int... args) {
var isSuccess = true;
for (var i = 0; i < args.length - 1; i++) {
if (args[i] < args[i + 1]) {
isSuccess = false;
break;
}
}
return isSuccess;
}
// Check order
private static String checkOrder(int... args) {
return isAscending(args) ? "xếp theo thứ tự tăng dần"
: isDescending(args) ? "xếp theo thứ tự giảm dần" : "chưa được sắp xếp";
}
// Check out
private static void checkOut() {
if (credit() == 1) {
run();
}
}
}