The exception tells you that at runtime your args array doesn't have any entries.
You change that by invoking the JVM like
java TestCase A B C
In other words: that array holds the parameters that you give to the JVM when starting it. No parameters on the command line ... ends up in an empty array.
Or giving another view: your code contains two assumptions about the incoming data:
- Using
args [0] requires that the array has at least one entry
- Using
....charAt(0) requires that this first entry as at least one character
And guess what: that isn't necessarily true!
You learned your first, very valuable lesson about programming: do not expect that "reality" at runtime just matches your assumptions how it should look like.
Meaning: when data is coming in from the outside, the first step is to validate that it meets your expectations. Like:
if (args.length > 0) {
... process input
} else {
tell user: no input
Similar for that String processing you intend to do!
java TestCase Abcfor example to enter in the first casejava TestCase yourstring.