Created
May 25, 2020 03:44
-
-
Save airicbear/75b4f98695f0138eebed3d8483798754 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.Scanner; | |
class SumOfIntegers { | |
public static void main(String[] args) { | |
String pathToFile = args[0]; | |
File file = new File(pathToFile); | |
int sum = 0; | |
try (Scanner scanner = new Scanner(file)) { | |
while (scanner.hasNextInt()) { | |
sum += scanner.nextInt(); | |
} | |
} catch (FileNotFoundException e) { | |
System.out.println("No file found: " + pathToFile); | |
} | |
System.out.println(sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment