SumOfSines.java


Below is the syntax highlighted version of SumOfSines.java from §1.2 Built-in Types of Data.


/******************************************************************************
 *  Compilation:  javac SumOfSines.java
 *  Execution:    java SumOfSines t
 *
 *  Read in an angle t (in degrees) and print sin(2t) + sin(3t).
 *
 *  % java SumOfSines 30
 *  1.8660254037844386
 *
 ******************************************************************************/

public class SumOfSines {
    public static void main(String[] args) {
        double degrees = Double.parseDouble(args[0]);
        double radians = Math.toRadians(degrees);
        double sum = Math.sin(2 * radians) + Math.sin(3 * radians);
        System.out.println(sum);
    }
}


Copyright © 2000–2022, Robert Sedgewick and Kevin Wayne.
Last updated: Thu Aug 11 10:12:06 EDT 2022.