import java.io.*; class Average10 { /* A program that calculates the average of a series of integers read from a file. The integers are read until the end of file is encountered. The program prompts for the name of the file the numbers are to be read from. */ public static void main(String[] args) throws IOException { BufferedReader in = Text.open(System.in); BufferedReader fileReader; String filename=""; int sum=0,count=0,n; for(;;) { try { System.out.print("Enter file name to read from: "); filename=Text.readString(in); fileReader=Text.open(filename); break; } catch(FileNotFoundException e) { System.out.println("File "+filename+" not found"); } } try { for(;;) { n=Text.readInt(fileReader); sum+=n; count++; } } catch(EOFException e) { System.out.print("Average is: "+Text.writeDouble((double)sum/count,5,3)); System.out.println(); } } }