program to find square root of number in Java


In this core java programming tutorial we will write a program to find square root of number in Java using Math class.






Full Program/SourceCode / Example to find square root of number in Java using Math class>
import java.util.Scanner;
/*
* Write a program to find square root of number in Java using Math class
*/
public class SquareRootOfNumberInJava {
   public static void main(String[] args) {
          Scanner scanner = new Scanner(System.in);
          System.out.println("Enter number : ");
          int number = scanner.nextInt();
          //calculate square root of number in Java using Math class
          double squareRootOfNumber = Math.sqrt(number);
          System.out.println("square root of "+number+" = " + (squareRootOfNumber));
    
   }
}
/*OUTPUT
Enter number :
16
square root of 16 = 4.0
*/



So, in this core java programming tutorial we wrote a program to find square root of number in Java using Math class.


Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.



RELATED LINKS>


>Pattern/Pyramid generating programs



No comments:

Post a Comment