Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package harr4603_lab02;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- /**
- * @author Jordan Harris
- * @version 1.0
- *
- */
- public class ScannerTest
- {
- public static void main(String[] args)
- {
- System.out.println("Enter a series of integers. Press 'q' to quit.");
- // Read from the keyboard.
- Scanner s = new Scanner(System.in);
- String result = "";
- int total = 0;
- result = s.next();
- while (!result.equals("q"))
- {
- result = s.next();
- try
- {
- total += Integer.parseInt(result);
- }
- catch(NumberFormatException nfe)
- {
- System.out.println("Invalid entry!");
- }
- }
- s.close();
- System.out.println("The total is " + total);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement