Find square root of a number using Math.sqrt in Java

Description

The following code shows how to find square root of a number using Math.sqrt.

Example


/*  w w w  .j  av  a  2s.  c om*/
public class Main {
  public static void main(String[] args) {
    // returns square root of 9, i.e. 3
    System.out.println(Math.sqrt(9));
    // returns square root of 25.5
    System.out.println(Math.sqrt(25.5));
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization