File tree 1 file changed +7
-4
lines changed
src/com/github/jonathanbirkey/chapter05
1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 2
2
* @author : Jonathan Birkey
3
3
* @mailto : jonathan.birkey@gmail.com
4
4
* @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))
8
7
*/
9
8
package com .github .jonathanbirkey .chapter05 ;
10
9
11
10
public class Exercise35 {
12
11
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 );
14
17
}
15
18
}
You can’t perform that action at this time.
0 commit comments