Guest User

Untitled

a guest
Apr 19th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3. import java.util.*;
  4.  
  5. public class HelloWorld{
  6.    
  7.  
  8.      public static void main(String []args){
  9.          String line = "7*8";
  10.          String pattern = "[0-9]+|[*/+-]";
  11.         System.out.println("Hello World");
  12.         Pattern r = Pattern.compile(pattern);
  13.  
  14.       // Now create matcher object.
  15.       Matcher m = r.matcher(line);
  16.       List<String> output = new ArrayList<String>();
  17.       while(m.find()) {
  18.          output.add(m.group());
  19.       }
  20.       String a[] = output.toArray(new String[0]);
  21.       switch(a[1]){
  22.           case "*":
  23.               System.out.println(Integer.parseInt(a[0])*Integer.parseInt(a[2]));
  24.       }
  25.      }
  26. }
Add Comment
Please, Sign In to add comment