8 Replies Latest reply: Jun 28, 2008 3:01 PM by 807589 RSS

    ArrayIndexOutOfBoundsException question

    807589
      Please forgive me if this is an easy answer or a dumb mistake. I run this code, enter a number, and instead of making a list of n random numbers from 0 - 100 and printing them out, I get a ArrayIndexOutOfBoundsException error.

      public class NumberHelp
      {
           public static void main (String[] args) 
           {
                Random r = new Random();
                Scanner keys = new Scanner(System.in);
                
                System.out.println("How many items in list?");
                int input = keys.nextInt();
                int[] list = new int[input];
                
                for (int i=0; i<=list.length; i++)
                {
                     list[i] = r.nextInt(101);
                }
                
                for(int i=0; i<=list.length; i++)
                {
                     System.out.print(list);
                }
                
                
           }
      }
      I'm new to Java...so go easy on me. Thanks.