INTRODUCTION TO COMPUTER SCIENCE
Robert Sedgewick and Kevin Wayne


This is the syntax highlighted version of DoubleOps.java.

/*************************************************************************
 *  Compilation:  javac DoubleOps.java
 *  Execution:    java DoubleOps
 *  
 *  Illustrates various integer operations.
 *
 *  % java DoubleOps
 *  sin(0.5235987755982988) = 0.49999999999999994
 *  cos(0.5235987755982988) = 0.8660254037844387
 *  tan(0.5235987755982988) = 0.5773502691896257
 *  0.49999999999999994 / 0.8660254037844387 = 0.5773502691896256
 *  0.24999999999999994 + 0.7500000000000001 = 1.0
 *
 *************************************************************************/

public class DoubleOps { 
   public static void main(String[] args) {

      double s = Math.sin(Math.PI / 6);
      System.out.println("sin(" + Math.PI / 6 + ") = " + s);

      double c = Math.cos(Math.PI / 6);
      System.out.println("cos(" + Math.PI / 6 + ") = " + c);

      double t = Math.tan(Math.PI / 6);
      System.out.println("tan(" + Math.PI / 6 + ") = " + t);
      System.out.println(s + " / " + c + " = " + s / c);

      double r = s*s + c*c;
      System.out.println(s*s + " + " + c*c + " = " + r);
  }
}


Last updated: Wed Feb 11 18:07:23 EST 2004 .
Copyright © 2004, Robert Sedgewick and Kevin Wayne.