import java.util.Scanner; //To get input from user using Scanner()
import java.util.Stack; //To use Stack class
public class infixnotation {
public static void main(String[] args) {
int i=0; //Variable to run Loop
char ch;
Scanner input = new Scanner(System.in); //Using a Scanner to get input
String expression = input.nextLine(); //Getting input from user
Stack<Character> symbols = new Stack<>(); //Creating one stack symbols to store Operators
Stack<String> values = new Stack<>(); //Creating another stack to store Operands
while(i < expression.length()) //Loop to process the elements in user input
{
ch = expression.charAt(i); //Assigning element of user input to variable ch
int convert = ch; //A variable to convert character value to interger value
if(ch==’+’||ch==’*’||ch==’-‘||ch==’/’) //Condition for Operators +,*,-,/
{
symbols.push(expression.charAt(i));
}
else if((convert>47&&convert<58)||(convert>64&&convert<91)||(convert>96&&convert<123)) //Condition for Operands 0-9, A-Z, a-z
{
String str = “”;
str += expression.charAt(i);
values.push(str);
}
else if(ch==’)’) //Condition for a parentheses
{
String x = values.pop(); // Copying Operands after the Operator to String x
String y = values.pop(); // Copying the Operands before the Operator to String y
char z = symbols.pop(); //Copying the Operator to variable z
StringBuilder pool = new StringBuilder(); //Using pool variable to recontruct the stack
pool.append(“(“); //Ading left parenthese to the pool
pool.append(y); //Adding Operands before the Operator
pool.append(z); //Adding the operator
pool.append(x); //Adding Operands after the Operator
pool.append(“)”); //Adding right parenthese to the pool
values.push(pool.toString()); //Pushing the Pool to Operands stack
}
i++;
}
System.out.println(values.pop()); //Printing the Final stack
}
}