0
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 ?

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by delta_frost
0

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.

Edited by NormR1

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.