Have to write a program in Java that sums the following summation: from 1 / (1+S
ID: 3550442 • Letter: H
Question
Have to write a program in Java that sums the following summation: from 1 / (1+Sqrt(2))
+1 / (Sqrt(2)+Sqrt(3)) + 1 / (Sqrt(3)+Sqrt(4)).......1 / (Sqrt(624)+Sqrt(625)).
Here is what I have so far. Am I on the right track?
import java.util.Scanner;
public class GetCalcSum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double sum = 1;
double calculation = 0;
for (int i = 0; i <= 624; i++) {
calculation = (1 / (Math.pow(i, (1 / 2)) + Math.pow(i + 1, (1 / 2))));
sum += i;
}
System.out.printf("sum is: %0.8d", calculation);
}
}
Out put that it returns is 0.5. And when I do the same summation on a calculator as Sigma(1 / (Sqrt(x)+Sqrt(x+1)) ) from 1-624 the result is 24.