02-28-2013, 05:56 PM
This is from listing 5.2 - Passer.java
The lesson was to insert values for the text array so we could get some output. I have tried to do that with text[1] = "John"; text[2] = "Harry" etc.
class Passer{public static void main(String[] arguments) {
Passer passer = new Passer();
passer.toUpperCase(arguments);
for (int i = 0; i < arguments.length; i++) {
System.out.print(arguments[i] + " ");
}
//next line is 8
System.out.println();
}
void toUpperCase(String[] text) {
text[1] = "John";
text[2] = "Harry";
text[3] = "Mary";
// next line is 16
for (int i = 0; i < text.length; i++) {
text[i] = text[i].toUpperCase();
}
}
}
It generates the error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at Passer.toUpperCase(Passer.java:16)
at Passer.main(Passer.java:8)
Any help would be appreciated.
The lesson was to insert values for the text array so we could get some output. I have tried to do that with text[1] = "John"; text[2] = "Harry" etc.
class Passer{public static void main(String[] arguments) {
Passer passer = new Passer();
passer.toUpperCase(arguments);
for (int i = 0; i < arguments.length; i++) {
System.out.print(arguments[i] + " ");
}
//next line is 8
System.out.println();
}
void toUpperCase(String[] text) {
text[1] = "John";
text[2] = "Harry";
text[3] = "Mary";
// next line is 16
for (int i = 0; i < text.length; i++) {
text[i] = text[i].toUpperCase();
}
}
}
It generates the error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at Passer.toUpperCase(Passer.java:16)
at Passer.main(Passer.java:8)
Any help would be appreciated.