// Solution to CS 111A in-class exercise 7 by Craig Persiko
// In-class exercise #7: Write a program that inputs numbers on the command line, 
// and then displays all of them except the highest one. Use a for each loop at 
// least once in your program.

import java.util.Scanner;

public class RemoveMax
{
  public static void main(String[] args)
  {
    if(args == null || args.length == 0)
    {
      System.out.println("Please enter numbers on the command line");
      System.exit(0); // or return;
    }

    double[] a = new double[args.length];
    double max;

    for(int i=0; i<args.length; i++)
      a[i] = Double.parseDouble(args[i]);

    max = a[0];
    for(double num : a)
      if(num > max)
        max = num;

    System.out.println("Here are the numbers you entered, with the maximum removed:");
    for(double n : a)
      if(n != max)
        System.out.print(n + " ");

    System.out.println();
  }
}

/*
Here is some sample output:

[cpersiko@fog cs111a]$ java RemoveMax 98.5 74.2 105 55 98 88
Here are the numbers you entered, with the maximum removed:
98.5 74.2 55.0 98.0 88.0
[cpersiko@fog cs111a]$ java RemoveMax 10 9 8 7 6 5 4 3 2 1 0
Here are the numbers you entered, with the maximum removed:
9.0 8.0 7.0 6.0 5.0 4.0 3.0 2.0 1.0 0.0
*/


syntax highlighted by Code2HTML, v. 0.9