If
i
is equal to zero then it cannot be greater than
stackSize
. Unless the user enters a negative number.
for(int i= 0; i>stackSize; i++){
int answer2 = sc.nextInt(i);
Change the
for
statement to:
for(int i= 0; i < stackSize; i++){
int answer2 = sc.nextInt(i);