// Program Name                  ParseInts.java
// Course:                       CSE 1302J
// Student Name:                 Bradley Shedd
// Assignment Number:            Lab#7
// Due Date:                     10/20/2010
// Purpose:                      This program reads a line of text
//                               and prints the integers in the line. 

   import java.util.Scanner;

  
public class ParseInts
   {
     
public static void main(String[] args)
     {
        
int val, sum=0;
         Scanner scan =
new Scanner(System.in);
         String line;
     
         System.out.println(
"Enter a line of text");
         Scanner scanLine =
new Scanner(scan.nextLine());
     
        
while (scanLine.hasNext())
         {    
           
try
            { 
              val = Integer.parseInt(scanLine.next());
               sum += val;
            }
              
catch (NumberFormatException nfe)
               {
               }
         }
         System.out.println(
"The sum of the integers on this line is " + sum);
         System.out.println(
"Coded By: Bradley Shedd");
      }
  
   }

Homepage