Skip to content

Commit 5f2cabe

Browse files
committedMar 7, 2024
finished exercise 35
1 parent e67ea10 commit 5f2cabe

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
 

Diff for: ‎src/com/github/jonathanbirkey/chapter05/Exercise35.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
* @author : Jonathan Birkey
33
* @mailto : jonathan.birkey@gmail.com
44
* @created : 28Feb2024
5-
* <p>(Display leap years) Write a program that displays all the leap years, 10 per line, from
6-
* 101 to 2100, separated by exactly one space. Also display the number of leap years in this
7-
* period.
5+
* <p>(Summation) Write a program to compute the following summation:
6+
* <p>(1/1+sqrt(2)) + (1/sqrt(2)+sqrt(3)) + (1/sqrt(3)+sqrt(4)) + ... + (1/sqrt(624)+sqrt(625))
87
*/
98
package com.github.jonathanbirkey.chapter05;
109

1110
public class Exercise35 {
1211
public static void main(String[] args) {
13-
// TODO: solve
12+
double summation = 0;
13+
for (int i = 1; i <= 624; i++) {
14+
summation += 1 / (Math.sqrt(i) + Math.sqrt(i + 1));
15+
}
16+
System.out.printf("Summation = %f", summation);
1417
}
1518
}

0 commit comments

Comments
 (0)
Please sign in to comment.