Results 1 to 3 of 3
  1. #1
    Andrewbishop is offline Member
    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0

    Exclamation I am getting array index out of bounds exception.Can you please ccorrect my program ?

    public class Flips
    {
    public static void main(String[] args)
    {
    int T = Integer.parseInt(args[0]);
    Counter heads = new Counter("heads");
    Counter tails = new Counter("tails");
    for (int t = 0; t < T; t++)
    if (StdRandom.bernoulli(0.5))
    heads.increment();
    else tails.increment();
    StdOut.println(heads);
    StdOut.println(tails);
    int d = heads.tally() - tails.tally();
    StdOut.println("delta: " + Math.abs(d));
    }
    }
    the program simulates flips of coin whether it is head or tails. indentation is present in my eclipse ide.Please tell me why it give array index out of bounds exception error.This is error i get.
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at Flips.main(Flips.java:5)

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: I am getting array index out of bounds exception.Can you please ccorrect my progr

    I'm guessing: (based on the linenumber) your args array is empty :P
    Command-Line Arguments (The Java™ Tutorials > Essential Classes > The Platform Environment)

  3. #3
    Huskies's Avatar
    Huskies is offline Member
    Join Date
    Jul 2011
    Posts
    47
    Rep Power
    0

    Default Re: I am getting array index out of bounds exception.Can you please ccorrect my progr

    If you use the "code" tags, then it will be much easier to read.

    What does your variable "T" represent?

Similar Threads

  1. array index out of bounds exception, AGAIN!
    By samanyu in forum New To Java
    Replies: 8
    Last Post: 06-08-2011, 11:27 AM
  2. Help Array Index out of bounds exception
    By star400040 in forum New To Java
    Replies: 2
    Last Post: 12-10-2010, 10:24 PM
  3. Array Index Out Of Bounds Exception
    By manowar689 in forum New To Java
    Replies: 3
    Last Post: 06-18-2010, 11:25 PM
  4. array Index out of Bounds exception== 0
    By Allgorythm in forum New To Java
    Replies: 6
    Last Post: 02-11-2010, 04:02 PM
  5. Array Index Out of Bounds Exception
    By kool001 in forum New To Java
    Replies: 1
    Last Post: 12-03-2009, 07:42 AM

Tags for this Thread

Posting Permissions

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