Skip to content

Commit 96e85c4

Browse files
author
Hud
committed
GITA MASALA
1 parent ea113a5 commit 96e85c4

File tree

12 files changed

+115
-0
lines changed

12 files changed

+115
-0
lines changed
1.23 KB
Binary file not shown.
1.23 KB
Binary file not shown.
970 Bytes
Binary file not shown.
1 KB
Binary file not shown.
1.27 KB
Binary file not shown.
1.05 KB
Binary file not shown.
1023 Bytes
Binary file not shown.

src/fori/For1.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package fori;
2+
3+
public class For1 {
4+
5+
public static void main(String[] args) {
6+
7+
solution(5, 10);
8+
}
9+
10+
public static void solution(int k, int n) {
11+
// k sonini n marta chop etilsin
12+
for (int i = 1; i <= n; i++) {
13+
System.out.print(String.format("%d: %d\n", i, k));
14+
}
15+
}
16+
}

src/fori/For10.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package fori;
2+
3+
public class For10 {
4+
5+
public static void main(String[] args) {
6+
solution(4);
7+
}
8+
9+
// s = 1 + 1/2 + 1/3 +1/4+...+ 1/n;
10+
public static void solution(int n) {
11+
double s = 0;
12+
for (int i = 1; i <= n; i++) {
13+
s += 1.0 / i;
14+
}
15+
System.out.println(s);
16+
}
17+
}

src/fori/For13.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package fori;
2+
3+
public class For13 {
4+
5+
public static void main(String[] args) {
6+
solution(3);
7+
}
8+
9+
/**
10+
* @param n n>0 bo'lgan butun son
11+
* 1.1 - 1.2 + 1.3 - 1.4 + 1.5 + ... + n
12+
*/
13+
public static void solution(int n) {
14+
double sum = 0; // summani hisoblash uchun
15+
int ishora = 1; // 1, -1
16+
for (double i = 1.1; i <= n; i += 0.1) {
17+
// i: 1.1, 1.2, 1.3, 1.4, 1.5... n
18+
sum += ishora * i; // -1 * 1.2
19+
ishora *= -1; // -1
20+
}
21+
22+
System.out.println(sum);
23+
}
24+
}

0 commit comments

Comments
 (0)