Use static import to bring sqrt() and pow() into view. : Static Import « Language Basics « Java






Use static import to bring sqrt() and pow() into view.

Use static import to bring sqrt() and pow() into view.

import static java.lang.Math.pow;
import static java.lang.Math.sqrt;

public class Hypot {
  public static void main(String args[]) {
    double side1, side2;
    double hypot;

    side1 = 3.0;
    side2 = 4.0;

    hypot = sqrt(pow(side1, 2) + pow(side2, 2));

    System.out.println("Given sides of lengths " + side1 + " and " + side2 + " the hypotenuse is "
        + hypot);
  }
}


           
       








Related examples in the same category

1.Static import user defined static fields.
2.Static Import
3.Java static import: old wayJava static import: old way
4.Java static import: System.out and errJava static import: System.out and err
5.Static import: sort
6.Java static import enum