import java.io.*; class Average4 { // 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. public static void main(String[] args) throws IOException { BufferedReader in = Text.open(System.in); int sum=0,count=1,n; System.out.print("Enter number 1 (or -999 to finish): "); n=Text.readInt(in); while(n!=-999) { sum+=n; count++; System.out.print("Enter number "+count+" (or -999 to finish): "); n=Text.readInt(in); } System.out.println("Average is: "+Text.writeDouble((double)sum/(count-1),5,3)); } }