Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

Explanation / Answer

import java.util.*; import java.lang.*; import java.io.*; public class GetCalcSum { public static void main (String[] args) throws java.lang.Exception { Scanner input = new Scanner(System.in); double sum = 0; double calculation = 0; for (int i = 1; i <= 624; i++) { calculation = Math.pow(i, 0.5) + Math.pow(i + 1, 0.5); calculation = 1/calculation; sum += calculation; } String total = Double.toString(sum); System.out.println("sum is: "+ sum); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote