- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class GetSum {
- public static void main(String[] args) {
- String s = "1ima7 j1 1hh1 0ttr1dfg10";
- Pattern p = Pattern.compile("[0-9]");
- Matcher m = p.matcher(s);
- int sum = 0;
- while (m.find()) {
- sum += Integer.parseInt(m.group());
- }
- System.out.println(sum);
- }
- }
2016-07-18
write a program to find sum of integers from a string
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment