So I'm getting the compiler error that I'm missing a return statement and I have looked at the other similar questions but I'm still confused about this matter.
public String pop()
{
try
{
if(top == -1)
{
throw new EmptyStackException("The stack is empty!");
}
String x = stack[top];
top--;
return x;
}
catch (EmptyStackException e)
{
System.out.println("The stack is empty!");
}
}
I apologize in advance if this question has been asked before but I have looked at various others and I cannot seem to figure this out.
See Question&Answers more detail:os