Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package praktikum5;
- import java.util.Stack;
- public class PostfixToInfix {
- public static void main(String[] args) {
- String input = "1234+*+";
- char[] persamaan = input.toCharArray();
- Stack<String> stack = new Stack<>();
- for (int i = 0; i < persamaan.length; i++) {
- char c = persamaan[i];
- if (c == '+' || c == '-' || c == '*' || c == '/' || c == '^') {
- String c1 = stack.pop();
- String c2 = stack.pop();
- String s = "(" + c1 + c + c2 + ")";
- stack.push(s);
- }
- else {
- stack.push(Character.toString(c));
- }
- }
- System.out.println(stack.pop());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement