Distinct.java


Below is the syntax highlighted version of Distinct.java.


  /************************************************************************
   * Compile: javac Distinct.java
   * Execute: java Distinct int0 int1 int2 ...
   * 
   * Input:   a list of integers
   * Output:  true if the inputs all have different values, false otherwise
   * 
   * > java Distinct 11 23 -7 0 99 5 42
   * true
   * 
   * > java Distinct 2 4 6 3 6
   * false
   * 
   * > java Distinct -3 -2 -1 -0 +3 +2 +1 +0 
   * false 
   * (Note: the reason is that the integer -0 equals the integer +0.)
   ***********************************************************************/

 public class Distinct {
     public static void main(String[] args) {
 
         int N = args.length;    
         
         // convert each arg and store them in an array of integers
         int[] values = _______________________________;
         for (int i = 0; _______________; _________)
             ________________ = Integer.parseInt(args[i]);    
        
         // are all of the pairs examined so far distinct?
         boolean result = true;

         // we'll examine each values[i] in the array 
         for (int i = 0; i < N; i++) {
             // we'll examine values[j] for each other j
             for (int j = _____; _________; _________) {
                 // are they different or not?
                 if (________________________________) {
                     result = _______________;
                 }
             }
         }
         
         System.out.println(result);
     }
 }