Rump.java


Below is the syntax highlighted version of Rump.java from §9.1 Scientific Computation.



/******************************************************************************
 *  Compilation:  javac Financial.java
 *  Execution:    java Financial
 *
 *  % java Remarkable
 *  1.1726039400531787
 *  6.338253E29
 *  -0.82739605994682136814

 *
 ******************************************************************************/


public class Rump {

    public static void example1() {
        float a = 665857, b = 470832;
        StdOut.println("a*a - 2  *b*b = " + (a*a - 2*b*b));
        StdOut.println("a*a - 2.0*b*b = " + (a*a - 2.0*b*b));
    }

    public static void example2() {
        double x = 10864.0, y = 18817.0;
        StdOut.println("9*x*x*x*x - y*y*y*y + 2*y*y = "+ (9*x*x*x*x - y*y*y*y + 2*y*y));
    }

    public static void example5() {
        double x = 0.707107;
        double p = 8118*x*x*x*x - 11482*x*x*x + x*x + 5741*x - 2030;
        StdOut.println("p(x) = "+ p);
    }

    public static void main(String[] args) {
        example1();
        example2();
        example5();
     }

}


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