Prateek sir and coding Stacks and queues

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T>0) {
int N = sc.nextInt();

	Stack<Integer> s = new Stack<>();
	
	if(N==2) {
		int S = sc.nextInt();
		s.push(S);
	}
	
	if(N==1) {
		if(!s.isEmpty()) {
		int rv = s.pop();
		System.out.println(rv);
		}
		else if(s.isEmpty()){
		 System.out.println("No Code");
		}
	}
	
	T--;
}

}
}

// My this code is note working can please tell what is wrong in the code

@Siddharth_sharma1808
you are creating a new stack for each query you should initialize your stack above the while loop.

import java.util.*;
public class temp2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
Stack s = new Stack<>();
while(T>0) {
int N = sc.nextInt();

if(N==2) {
	int S = sc.nextInt();
	s.push(S);
}

if(N==1) {
	if(!s.isEmpty()) {
	int rv = s.pop();
	System.out.println(rv);
	}
	else if(s.isEmpty()){
	 System.out.println("No Code");
	}
}

T--;

}
}
}