INTRODUCTION TO COMPUTER SCIENCE
Robert Sedgewick and Kevin Wayne


This is the syntax highlighted version of Random.java.

/*************************************************************************
 *  Compilation:  javac Random.java
 *  Execution:    java Random N
 *
 *  Prints N integers between 0 and 99.
 *
 *  % java Random 5
 *  90 45 71 38 22
 *
 *************************************************************************/

class Random { 
    public static void main(String[] args) {
        int N = Integer.parseInt(args[0]);
        for (int i = 0; i < N; i++) {
            int r = (int) (Math.random() * 100);
            System.out.print(r + " ");
        }
        System.out.println();
    }
}


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