3 / 3
May 2019

import java.util.;
import java.lang.
;
import java.io.*;

class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
Stack stack = new Stack();
String exp,temp;
char ch;
int i;
String tst = sc.nextLine();
int t = Integer.parseInt(tst);
while(t>0)
{
exp = sc.nextLine();
System.out.println(exp);
for(i=0;i<exp.length();i++)
{
ch = exp.charAt(i);
if(ch!=’)’)
{
temp=String.valueOf(ch);
stack.push(temp);
}
else
{
temp=stack.pop();
temp+=stack.pop();
temp=stack.pop()+temp;
stack.pop();
stack.push(temp);
}
}
System.out.println(stack.pop());
t-=1;
}
}
}

  • created

    Apr '19
  • last reply

    May '19
  • 2

    replies

  • 860

    views

  • 2

    users

  • 3

    links

I’m guessing ONP2?

When I try your code, I get a compilation error. Did something not make it through in your post?

Compilation error #stdin compilation error #stdout 0s 0KB
Main.java:30: error: incompatible types: Object cannot be converted to String
temp=stack.pop();