public static void sumOfSquareRoots() {
        Scanner scan = new Scanner( System.in );
        double value;

        // read in a double
        System.out.print  ("Enter a double:");
        value = scan.nextDouble();

        // calculate its square root
        double result = Math.sqrt( value );

        // write out the result
        System.out.println("square root of your number is " + result );
        System.out.println("The sum of square root of numbers is"+result);
      }

"This calculates the square root of a given number how do I add multiple numbers and add the sum of the square roots ?

Recommended Answers

All 2 Replies

how do I add multiple numbers

Make a loop that asks for a number, reads the number, does a computation with the number
and then loops back to the top where it asks for the number again.
To end the loop either ask the user before entering the loop for the number of inputs that will be made OR have a special number(like 0) that the user enters that tells the program to exit the loop.

In the scanner object,use a while loop with the condition hasNextDouble() method.By this the user can input any number of doubles at a single go.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.