UNB/ CS/ David Bremner/ teaching/ java/ Sentinel2.java
public class Sentinel2
{  public static void main(String[] args)
   {  ConsoleReader console = new ConsoleReader(System.in);
      System.out.println("Enter data (Q to finish):");
      
      double sum = 0;
      int count = 0;

      // compute sum of all input values
      
      boolean done = false;
      while (!done)
      {  String inputLine = console.readLine();
         if (inputLine.equalsIgnoreCase("Q"))
            done = true;
         else
         {  double x = Double.parseDouble(inputLine);
            sum = sum + x;
            count++;
         }
      }
      
      // compute average
      
      if (count == 0) 
         System.out.println("No data");
      else 
         System.out.println("Average = " + sum / count);
   }
}