Results 1 to 5 of 5
Thread: ArrayIndexOutOfBounds Help
- 11-11-2012, 06:46 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 20
- Rep Power
- 0
ArrayIndexOutOfBounds Help
I have to use a try block to loop through each item in the array and increase a subscript by 1. Then I have to use a catch block that catches the ArrayIndexOutOfBoundsException and displays a message.
I cant seem to get it to throw the message: Now Youve Gone Too Far. How do I go about creating this message as it tries to display a 6th number that is not in the array?
PHP Code://GoTooFar.java by Tyler 11/11/2012 import java.util.*; public class GoTooFar { public static void main(String[] args) { Date today = new Date(); try { //Display intro window System.out.println("GoTooFar" + "\nby Tyler " + today); //Initialize arrays int[] numbers = {10 , 11 , 12 , 13 , 14}; //Display each number in array for (int i = 0; i < numbers.length; ++i) { System.out.print(numbers[i] + "\n"); } } catch(ArrayIndexOutOfBoundsException exception) { System.out.println("Now Youve gone too far"); System.exit(0); } } }
- 11-11-2012, 07:18 PM #2
Re: ArrayIndexOutOfBounds Help
Well, your loop doesn't try to go too far.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 11-11-2012, 08:11 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 20
- Rep Power
- 0
- 11-11-2012, 08:47 PM #4
Member
- Join Date
- Nov 2012
- Posts
- 6
- Rep Power
- 0
Re: ArrayIndexOutOfBounds Help
Java Code:for (int i = 0; i <= numbers.length; ++i) { System.out.print(numbers[i] + "\n"); }
- 11-11-2012, 08:51 PM #5
Member
- Join Date
- Oct 2012
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
ArrayIndexOutOfBounds Error, Any help would be appreciated.
By Jtrtoday in forum New To JavaReplies: 3Last Post: 04-09-2012, 04:30 PM -
problem with ArrayIndexoutofbounds exception
By hyma19 in forum New To JavaReplies: 1Last Post: 01-16-2012, 10:13 AM -
ArrayIndexOutOfBounds, JTable.getValueAt
By ZackO in forum AWT / SwingReplies: 10Last Post: 10-17-2010, 07:29 PM -
ArrayIndexOutofBounds Exception
By atul.goldenstring in forum New To JavaReplies: 10Last Post: 04-10-2010, 10:47 AM -
ArrayIndexOutOfBounds
By SwEeTAcTioN in forum New To JavaReplies: 6Last Post: 12-07-2009, 12:59 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks