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

      // compute sum of all input values
      
      boolean done = false;
      while (!done)
      {  String inputLine = console.readLine();
         double x = Double.parseDouble(inputLine);
         if (x == 0)
            done = true;
         else
         {  sum = sum + x;
            count++;
         }
      }
      
      // compute average

      if (count == 0) 
         System.out.println("No data");
      else 
         System.out.println("Average = " + sum / count);
   }
}