Ask 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 must output each number and its square root.)

+4
Answers (1)
  1. 25 August, 08:23
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers