IntCounter - public static void main(String args int count = 0 i try Scanner input = new Scanner(new File"input" System.out.println

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // IntCounter.java Author: Lewis/Loftus // // Demonstrates the use of the hasNextInt and nextInt methods of // of the Scanner class to parse input from a text file. //******************************************************************** / import java.io.*; import java.util.Scanner; i public class IntCounter { //----------------------------------------------------------------- // Counts the number of integers read from a text file and then // prints a table of the integers and a total count of integers // found in the file. //-----------------------------------------------------------------
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public static void main (String args) { int count = 0; i try { Scanner input = new Scanner(new File("input.txt")); System.out.println (); System.out.println ("Integers found: "); S while (input.hasNextInt()) { System.out.print (input.nextInt() + " "); count++; } System.out.println (); System.out.println (); System.out.println (count + " total integers found."); } catch (FileNotFoundException exception) { System.out.println ("The input file was not found!"); } catch (IOException exception) { System.out.println (exception); } } }...
View Full Document

This note was uploaded on 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Ask a homework question - tutors are online