How can i resolve run error?
import java.util.*;
public class Main
{
public static void main (String args[]) throws Exception
{
// Dequeue obj = new Dequeue();
Scanner sc= new Scanner(System.in);
int n= sc.nextInt();
for(int i=0;i<n;i++)
{
enqueue(sc.nextInt());
}
for(int i=0;i<n;i++)
{
System.out.print(dequeue()+" ");
}
}
static Stack s1= new Stack<>();
static Stack s2= new Stack<>();
public static void enqueue(int item) throws Exception
{
try
{
while(!s1.isEmpty())
{
s2.push(s1.pop());
}
s1.push(item);
while(!s2.isEmpty())
{
s1.push(s2.pop());
}
}
catch (Exception e)
{
throw new Exception("queue is full");
}
}
public static int dequeue() throws Exception
{
try
{
int x=s1.peek();
s1.pop();
return x;
}
catch (Exception e)
{
throw new Exception ("queue is empty");
}
}
}