Created
June 27, 2016 09:25
-
-
Save hamburger1984/cab5982eb3effab0c75fcba9ceef3ef7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment