Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sam's Teach Yourself Java in 21 Days?
#18
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.
Reply


Messages In This Thread
RE: Sam's Teach Yourself Java in 21 Days? - by MikeSmith1 - 02-28-2013, 05:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  why java haphazard 8 1,521 12-12-2011, 03:23 AM
Last Post: RDCA
  Need Java help from java expert. Blazin 2 1,934 09-07-2011, 02:43 PM
Last Post: AceInfinity
  Java help php 1 844 04-06-2010, 06:41 AM
Last Post: php
  Java Problem for real java programmer Testgamma1 10 4,592 03-14-2010, 09:08 AM
Last Post: uber1337
  How do i get java Mozz 4 1,336 02-13-2010, 12:29 PM
Last Post: Mozz

Forum Jump:


Users browsing this thread: 1 Guest(s)