Math Functions

There are many Math functions in Java. Here is an illustration of the square root function:

1
2
3
4
5
6
7
8
9
10
package somePackage;
import java.util.*;
public class InchesTable {
  public static void main(String[] args) {
    Scanner keyboard=new Scanner(System.in); //do just once
    System.out.print("Enter a number:");
    double number=keyboard.nextDouble();
    System.out.println("The square root of " + number + " is "+Math.sqrt(number)); 
  }//main
}//class
CODE

Here is one example of the output:

Enter a number:99
The square root of 99.0 is 9.9498743710662

NEXT: