Ask Question
31 January, 07:30

Write a Program that uses the method sqrt. of the class Math and outputs the square roots of the first 25 positive integers. (Your program must output each number and its square root.)

+3
Answers (1)
  1. 31 January, 10:14
    0
    The program to this question can be given as:

    Program:

    import java. lang.*;

    class root / /define class

    {

    int i; / /define variable

    public void Squareroot ()

    //define function

    {

    System. out. println ("Number/tsquare root"); / /print message.

    for (i=1; i<=25; i++) / /use for loop

    {

    System. out. println (i+"/t"+Math. sqrt (i)); / /print value and using square root function

    }

    }

    }

    public class Main / /define class

    {

    public static void main (String[] ar) / /define main method

    {

    root ob = new root (); / /create class object

    ob. Squareroot ();

    calling function

    }

    }

    output:

    Number Square Root

    1 1.0

    2 1.414

    3 1.732

    4 2.0

    5 2.236

    .

    .

    .

    24 4.898

    25 5.0

    Explanation:

    In the above program firstly we declare a class that is root. In this class, we declare a variable (i) and function (Squareroot). In the function, we define a loop that uses the variable to print all the values. In the loop, we use the math square root function that is sqrt. This function is bind in java package i. e java. lang.*; This function returns square root that's value type is double. Then we define a main class in the main class we define the main function in the main function we create a root class object and call the function.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a Program that uses the method sqrt. of the class Math and outputs the square roots of the first 25 positive integers. (Your program ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers