-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopExercise.java
More file actions
45 lines (40 loc) · 1.08 KB
/
LoopExercise.java
File metadata and controls
45 lines (40 loc) · 1.08 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
package exercise_loop;
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 LoopExercise {
public static void main(String[] args) {
// tit
out.println(BLUE_BOLD);
printlnAdv("Loop Exersice");
// content
run();
}
// Main
private static void run() {
// cap
out.println();
printAdv(GREEN, "Nhập vào số nguyên dương: ", RESET);
// output
printlnAdv(YELLOW, format("Kết quả biểu thức là: %s", writePerfectDub(calculator(numLimit(1, MAX_VALUE)))));
out.println();
// ctrl
checkOut();
}
// Calculator
private static double calculator(int n) {
var sum = 0d;
for (var i = 1; i <= n; i++) {
sum += (double) 1 / (i * (i + 1) * (i + 2));
}
return sum;
}
// Check out
private static void checkOut() {
if (credit() == 1) {
run();
}
}
}