import java.util.*;
public class Main {
public static void main(String args[]){
try{
Stack s=new Stack();
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++){
int a=sc.nextInt();
if(a==2){
int k=sc.nextInt();
s.push(k);
}
if( a==1){
int g=s.peek();
System.out.println(g);
s.pop();
}
}
}
catch(Exception e){
System.out.println(e);}}
}
it is showing wrong answer ,what wrong with my code.
Prateek Sir and Coding
@Sweta,
https://ide.codingblocks.com/s/196506 corrected code.
Error: Not printing “No Code” if the stack is empty.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.