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