Advertisement
bojidar_blagoev

Untitled

Sep 19th, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.util.Scanner;
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class _Problem_3_SimpleExpression {
  7.     public static void main(String[] args) {
  8.         Scanner in = new Scanner(System.in);
  9.         String[] parts = in.nextLine().split(" ");
  10.         String expression = "";
  11.         for (String part : parts) {
  12.             expression += part;
  13.         }
  14.         Pattern pattern = Pattern.compile("-[0-9. ]+|[0-9.]+");
  15.         Matcher m = pattern.matcher(expression);
  16.         BigDecimal result = new BigDecimal("0");
  17.         while (m.find()) {
  18.             result = result.add(new BigDecimal(m.group()));
  19.         }
  20.         System.out.println(result);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement