Examples of smaller Java programs that do various interesting things.

ReadAndPrintScores.java 377B

123456789101112131415161718
  1. import java.util.Scanner;
  2. import java.io.File;
  3. import java.io.IOException;
  4. public class ReadAndPrintScores
  5. {
  6. public static void main(String[] args)
  7. { try
  8. { Scanner s = new Scanner( new File("scores.dat") );
  9. while( s.hasNextInt() )
  10. { System.out.println( s.nextInt() );
  11. }
  12. }
  13. catch(IOException e)
  14. { System.out.println( e );
  15. }
  16. }
  17. }