This code is meant to receive a String input such as "PUSH 5" and take the 5 from the string turn it into an int and do the push command. However I keep getting the string index out of range error on the line "char s = ar[i].charAt(1);" Any ideas?
import java.util.*;
public class lab6
{
public static void main(String []args)
{
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
lab6stack theStack = new lab6stack(size);
String [] ar = new String [size];
for(int i = 0; i < size; i++)
{
ar[i] = sc.nextLine();
char s = ar[i].charAt(1);
if(s == 'U')
{
int num = Integer.parseInt(ar[i].substring(5));
theStack.push(num);
}
else if(s == 'O')
{
theStack.pop();
}
}
while (!theStack.isEmpty())
{
System.out.println(theStack.pop());
}
}
}