Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.util.Scanner;
- import java.io.FileNotFoundException;
- public class AddingUpSalaries {
- public static void main(String[] args) throws FileNotFoundException {
- int sum = 0;
- File salariesFile = new File("StaffData.txt");
- try{
- Scanner scan = new Scanner(salariesFile);
- while(scan.hasNext()) {
- if (!scan.hasNextInt())
- scan.next();
- else {
- int nextnum = scan.nextInt();
- System.out.println(nextnum);
- sum += nextnum;
- }
- }
- System.out.println("Total salary is" + sum);
- scan.close();
- }
- catch(FileNotFoundException ex){
- System.err.println(salariesFile.getName()+" does not exist");
- }
- System.out.println("Finished");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement