Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Evaluate{
- public static void main(String[] args){
- String[] samples = new String[]{
- " 5 + 6 * 7 /2",
- "5/2",
- "500/(3+2)",
- "5^2/4"
- };
- Evaluate e = new Evaluate();
- for(String s: samples){
- e.run(s);
- }
- }
- public float run(String input){
- System.out.println("--- " + input + " -> " + normalize(input) + " ---");
- Scanner s = new Scanner(normalize(input));
- while(s.hasNext()){
- System.out.println(s.next());
- }
- return 0.0f;
- }
- private String normalize(String input){
- return input.replaceAll("\\s*([()+\\*/^-])\\s*", " $1 ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement