Plot.java


Below is the syntax highlighted version of Plot.java from §2.4 Input and Output.

/*************************************************************************
 *  Compilation:  javac Plot.java
 *  Execution:    java Plot < data.txt
 *  Dependencies: StdDraw.java StdIn.java
 *
 *  Reads in (x, y) values from standard input and plots them using
 *  the StdDraw graphics library.
 *
 *  Assumption: all x and y coordinates are between 0 and 512.
 *
 *  % java Plot
 *  100.0 200.0
 *  222.2 456.3
 *  331.6 401.2
 *  <Ctrl-d>
 *
 *************************************************************************/

public class Plot {

    public static void main(String args[]) {
        StdDraw.create(512, 512);
        while (!StdIn.isEmpty()) {
            double x = StdIn.readDouble();
            double y = StdIn.readDouble();
            StdDraw.go(x, y);
            StdDraw.spot();
        }
        StdDraw.show();
    }

}


Last updated: Wed Sep 22 10:23:44 EDT 2004 .
Copyright © 2004, Robert Sedgewick and Kevin Wayne.