Guest User

Untitled

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