Advertisement
coasterka

#3SumNumsFromTxtFile

May 15th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4.  
  5. public class SumNumsFromTxtFile {
  6.     public static void main(String[] args) throws IOException {
  7.         try(BufferedReader br = new BufferedReader(new FileReader("Input.txt"))) {
  8.             StringBuilder sb = new StringBuilder();
  9.             int result = 0;
  10.             String line = "";
  11.             while((line = br.readLine())!=null){
  12.                 result+=Integer.parseInt(line);
  13.             }          
  14.             System.out.print("Sum = " + result);
  15.         }
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement