-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSum.java
27 lines (25 loc) · 853 Bytes
/
Sum.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// This Program is to caculate sum of two integer
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Sum{
public static void main(String[]args){
if (args.length <= 0) {
System.out.println("Pls input your test case file");
return;
}
try {
File file = new File(args[0]);
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()){
String line = scanner.nextLine();
String[] array = line.split(" ");
int x = Integer.parseInt(array[0]);
int y = Integer.parseInt(array[1]);
System.out.format("The sum of %d and %d is: %d\n", x, y, x+y);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}