-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFor13.java
More file actions
24 lines (20 loc) · 566 Bytes
/
For13.java
File metadata and controls
24 lines (20 loc) · 566 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
package fori;
public class For13 {
public static void main(String[] args) {
solution(3);
}
/**
* @param n n>0 bo'lgan butun son
* 1.1 - 1.2 + 1.3 - 1.4 + 1.5 + ... + n
*/
public static void solution(int n) {
double sum = 0; // summani hisoblash uchun
int ishora = 1; // 1, -1
for (double i = 1.1; i <= n; i += 0.1) {
// i: 1.1, 1.2, 1.3, 1.4, 1.5... n
sum += ishora * i; // -1 * 1.2
ishora *= -1; // -1
}
System.out.println(sum);
}
}