Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.*;
- public class HelloWorld{
- public static void main(String []args){
- String line = "7*8";
- String pattern = "[0-9]+|[*/+-]";
- System.out.println("Hello World");
- Pattern r = Pattern.compile(pattern);
- // Now create matcher object.
- Matcher m = r.matcher(line);
- List<String> output = new ArrayList<String>();
- while(m.find()) {
- output.add(m.group());
- }
- String a[] = output.toArray(new String[0]);
- switch(a[1]){
- case "*":
- System.out.println(Integer.parseInt(a[0])*Integer.parseInt(a[2]));
- }
- }
- }
Add Comment
Please, Sign In to add comment