Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Sum {
- public static void main(String[] args) {
- int result = 0;
- for (int i = 0; i < args.length; i++) {
- args[i] = args[i].replaceAll("^\\s+","");
- String[] tmp = args[i].split("\\s+");
- for (int j = 0; j < tmp.length; j++) {
- try {
- result += Integer.parseInt(tmp[j]);
- }
- catch (NumberFormatException e) {
- System.out.println("Incorrect expression \"" + tmp[j] + "\", ignored.");
- }
- }
- }
- System.out.println("Result: " + result);
- }
- }
Add Comment
Please, Sign In to add comment