Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaLoopsMethodsClasses;
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- public class Ex8_SumNumsFromTextFile {
- public static void main(String[] args) throws IOException {
- try {
- BufferedReader in = new BufferedReader(new FileReader("Input.txt"));
- String line;
- int sum = 0;
- while ((line = in.readLine()) != null) {
- sum += Integer.parseInt(line);
- }
- System.out.println(sum);
- in.close();
- } catch (java.io.FileNotFoundException nfe) {
- System.out.println("Error");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement