import java.io.*; class Average5 { // A program that calculates the average of a series of integers. // It prompts for each one. A sentinel value is used to indicate the // end of the series. static final int SENTINEL = -999; public static void main(String[] args) throws IOException { BufferedReader in = Text.open(System.in); double average; int sum=0,count=1,n; System.out.print("Enter number 1 (or "+SENTINEL+" to finish): "); n=Text.readInt(in); while(n!=SENTINEL) { sum+=n; count++; System.out.print("Enter number "+count+" (or "+SENTINEL+" to finish): "); n=Text.readInt(in); } System.out.println("Average is: "+Text.writeDouble((double)sum/(count-1),5,3)); } }