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)
Re: I am getting array index out of bounds exception.Can you please ccorrect my progr
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?