Guest User

Untitled

a guest
Jun 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. public class SumArgs {
  2.     public static void main(String[] args) {
  3.         int sum = 0;
  4.         for (int i = 0; i < args.length; i++) {
  5.             String tmp[] = args[i].replaceAll("^\\s+", "").split("(\\s+)");
  6.             for (int j = 0; j < tmp.length; j++) {
  7.                 try {
  8.                     sum += Integer.parseInt(tmp[j]);
  9.                 }
  10.                 catch (NumberFormatException e) {
  11.                     e.printStackTrace();
  12.                     System.out.println("Invalid input: \"" + tmp[j] + "\", ignoring.");
  13.                 }
  14.             }
  15.         }
  16.         System.out.println(sum);
  17.     }
  18. }
Add Comment
Please, Sign In to add comment