Static Imports

/* StaticImports.java */

import static java.lang.Math.*;

public class StaticImports
{
  public static void main(String[] args)
  {
    double r = 1;
    
    System.out.println("r = " + r);
    System.out.println("pole = " + pole(r));

    System.out.println();

    double x = -1;
    
    System.out.println("x = " + x);
    System.out.println("|" + x + "| = " + modul(x));
  }

  static double pole(double r)
  {
    return PI*r*r; // <=> return Math.PI*r*r;
  }
  
  static double modul(double x)
  {
    return abs(x); // <=> return Math.abs(x);
  }
}
r = 1.0
pole = 3.141592653589793

x = -1.0
|-1.0| = 1.0
Press any key to continue...

Strona główna