Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class _Problem_3_SimpleExpression {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- String[] parts = in.nextLine().split(" ");
- String expression = "";
- for (String part : parts) {
- expression += part;
- }
- Pattern pattern = Pattern.compile("-[0-9. ]+|[0-9.]+");
- Matcher m = pattern.matcher(expression);
- BigDecimal result = new BigDecimal("0");
- while (m.find()) {
- result = result.add(new BigDecimal(m.group()));
- }
- System.out.println(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement