Java Program To Calculate Square Root Of Any Number - Java Program Example

Here we will see a java  program For calculate square root of any number we multiply number.


When run this java  program then compiler ask input a number for calculate square root that number which imputed by user. For eg - you enter 9, than compiler show squire root after compile 3 on screen.

Program Code  

 package com.androidpro.in;

import
java.io.BufferedReader;
import
java.io.IOException;
import
java.io.InputStreamReader;
import
java.util.Scanner;

public class
Main {

   
public static void main(String[] args) throws IOException
    {

       
int number = 0;
       
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

       
System.out.println("Enter a number to \ncalculate square root of any number");

       
String line = br.readLine();

        try
       
{
            number = Integer.parseInt(line)
;
       
}
       
catch (NumberFormatException exception)
        {
            System.
out.println("Please enter a valid number");
       
}
       
double squareRoot = Math.sqrt(number);
       
System.out.println("Square root of a number " + number + "=" + squareRoot);
   
}


}

 

Output

Enter a number to

calculate square root of any number

44

Square root of a number 44=6.6332495807108

 

Process finished with exit code 0

Post a Comment

0 Comments