Results 1 to 2 of 2
  1. #1
    javanubby is offline Member
    Join Date
    Mar 2012
    Posts
    8
    Rep Power
    0

    Default out of bound error

    Got an array out of bound error.... can someone tell me why?
    Java Code:
    import javax.swing.JOptionPane;
    public class Methods
    {
        public static void main(String arg[])
            {
             String sizeOfArray = JOptionPane.showInputDialog("How many pieces of data are there?");
             int a = Integer.parseInt(sizeOfArray);
             int[] arraySize = new int [a];
             for(int b = 1; b <= a; b++) {
                 String dataInput = JOptionPane.showInputDialog("Enter your "+b+"(st/nd/rd/th) number.");
                 int c = Integer.parseInt(dataInput);
                 c = arraySize[b];
                }
             String menuOptions = "Menu\n\n1. Find the Mean of the data\n2. Find the Median of the data\n3. Find the Mode of the data\n4. Exit";
             String response = JOptionPane.showInputDialog(menuOptions);
             int answer = Integer.parseInt(response);
             switch(answer) {
                case 1: //mean(list); 
                    break;
                case 2: //median(list);
                    break;
                case 3: //mode(list);
                    break;
                case 4: //exit
                    System.exit(0);
                    break;
                default:
                    JOptionPane.showMessageDialog(null, "Enter a valid option!(1-4)");
             }
        }
    }

  2. #2
    skynet357 is offline Member
    Join Date
    Mar 2012
    Location
    Hyderabad, India
    Posts
    8
    Rep Power
    0

    Default Re: out of bound error

    Java Code:
    for(int b = 1; b <= a; b++)
    Analyse this line once again and u will find the logical error

Similar Threads

  1. Out of Bound Exception Error
    By Calaminh in forum New To Java
    Replies: 6
    Last Post: 01-28-2012, 12:48 AM
  2. Array Index Out of Bound
    By ankiit in forum New To Java
    Replies: 9
    Last Post: 01-04-2012, 07:03 AM
  3. ArrayList out of bound, split string error.
    By Kerrai in forum New To Java
    Replies: 4
    Last Post: 11-03-2010, 10:37 AM
  4. Array index out of bound exception error
    By rahulkrishnanr in forum Threads and Synchronization
    Replies: 7
    Last Post: 10-12-2010, 06:57 PM
  5. [SOLVED] String out of bound error
    By maxb in forum New To Java
    Replies: 4
    Last Post: 12-01-2008, 03:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •