Welcome to Dream.In.Code
Become a Java Expert!

Join 150,381 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,233 people online right now. Registration is fast and FREE... Join Now!




ArayIndexoutOfBoundException

 
Reply to this topicStart new topic

ArayIndexoutOfBoundException

MarsCute
28 Jan, 2008 - 12:06 AM
Post #1

New D.I.C Head
*

Joined: 27 Jan, 2008
Posts: 3

the program must loop to display each element inputted by the user,increasing a subscript by one on each pass.

the problem here, it doesn't loop to display and ask the user to input until 5 has made!

thanks a lot!!!!

CODE

import java.io.*;
public class GoTooFar
{
      public static void main (String [] args) throws Exception
      {
             int nItems;
             int num []=new int[5];
            
             try{
                    System.out.println("Enter a Number");
                    num[nItems] = Integer.paseInt(in.readLine());
                    nItems++;}
            
             catch (ArrayIndexOutOfBoundException e)
             {
                     System.out.println ("Now you have gone too far!");
              }
        }
}


User is offlineProfile CardPM
+Quote Post

1lacca
RE: ArayIndexoutOfBoundException
28 Jan, 2008 - 12:29 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
There is no loop in the code at all (for, while, or do..while)
nItems is not initialized (there should be something like nItems=0; )
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:05PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month