Triangle.java


Below is the syntax highlighted version of Triangle.java from §1.5 Input and Output.


/******************************************************************************
 *  Compilation:  javac Triangle.java
 *  Execution:    java Triangle
 *  Dependencies: StdDraw.java
 *
 *  Plot a triangle.
 *
 ******************************************************************************/

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

        // 5% border
        StdDraw.setScale(-0.05, 1.05);

        // draw the triangle
        double t = Math.sqrt(3.0) / 2.0;
        StdDraw.line(0.0, 0.0, 1.0, 0.0);
        StdDraw.line(1.0, 0.0, 0.5, t);
        StdDraw.line(0.5, t, 0.0, 0.0);

        // draw the point; make pen radius large enough to see it
        StdDraw.setPenRadius(0.01);
        StdDraw.point(0.5, t/3.0);
    }
}


Copyright © 2000–2019, Robert Sedgewick and Kevin Wayne.
Last updated: Sun Feb 14 18:22:57 EST 2021.