AllEqual.java


Below is the syntax highlighted version of AllEqual.java from §1.3 Conditionals and Loops.


/******************************************************************************
 *  Compilation:  javac AllEqual.java
 *  Execution:    java AllEqual a b c
 *
 *  Prints "equal" if a = b = c and "not equal" otherwise.
 *
 *  % java AllEqual 10 10 10
 *  all equal
 *
 *  % java AllEqual 10 20 10
 *  not all equal
 *
 ******************************************************************************/

public class AllEqual {
    public static void main(String[] args) {
        int a = Integer.parseInt(args[0]);
        int b = Integer.parseInt(args[1]);
        int c = Integer.parseInt(args[2]);

        if (a == b && a == c) {
            System.out.println("all equal");
        }
        else {
            System.out.println("not all equal");
        }

    }
}


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