Ive written the code, according to me it should be correct. I am confused on how to take an another integer input when sa==2.
ArrayList list=new ArrayList();
for(int i=0;i<n;i++) {
int sa=s.nextInt();
if(sa==2) {
int cost=s.nextInt();
stack.push(cost);
}
else if(sa==1&&!list.isEmpty()) {
list.add(stack.pop());
}
}
for(int i:list) {
System.out.println(i);
}
Cant Understand what is going wrong
It is not working on eclipse also.
Also to print No Code should I print it int the codition sa==1 and break the for loop after that?
One test case is able to run.
Can you point out what is wrong in my code and how to fix it?
code is fine
just a change
if(s==1) {
if(stack.isEmpty()){
System.out.println(“No Code”);
}
else
System.out.println(stack.pop());
}
just a change
else if(s==1) {
if(!stack.isEmpty()){
list.add(stack.pop());
}
else {
System.out.println(“No Code”);
}
}