daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.File;
  2. import java.util.Scanner;
  3. import java.io.FileNotFoundException;
  4.  
  5. public class AddingUpSalaries {
  6.  
  7.     public static void main(String[] args) throws FileNotFoundException {
  8.  
  9.         int sum = 0;
  10.         File salariesFile = new File("StaffData.txt");
  11.         try{
  12.             Scanner scan = new Scanner(salariesFile);
  13.            
  14.             while(scan.hasNext()) {
  15.                 if (!scan.hasNextInt())
  16.                     scan.next();
  17.                 else {
  18.                     int nextnum = scan.nextInt();
  19.                     System.out.println(nextnum);
  20.                     sum += nextnum;
  21.                 }
  22.             }
  23.  
  24.  
  25.             System.out.println("Total salary is" + sum);
  26.             scan.close();
  27.         }
  28.         catch(FileNotFoundException ex){
  29.             System.err.println(salariesFile.getName()+" does not exist");
  30.         }
  31.         System.out.println("Finished");
  32.  
  33.     }
  34.  
  35. }
RAW Paste Data
Top