You only want to get to the "next part" if the first if is true. Consider nesting your if blocks, putting the if (answer == 'n'... bit inside the if (size > 0) bit.
Type: Posts; User: curmudgeon
You only want to get to the "next part" if the first if is true. Consider nesting your if blocks, putting the if (answer == 'n'... bit inside the if (size > 0) bit.
You would need to use an if block, similar to what you're doing above, and it would make most sense to check for the size immediately before the error, putting your code where you extract your first...
The String class has a method, length(), that tells you how long the String is. Consider checking this first before trying to extract a character that doesn't exist.