Results 1 to 3 of 3
- 08-10-2012, 07:38 PM #1
Member
- Join Date
- Aug 2012
- Posts
- 1
- Rep Power
- 0
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)
- 08-10-2012, 07:49 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
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)
- 08-11-2012, 12:55 AM #3
Similar Threads
-
array index out of bounds exception, AGAIN!
By samanyu in forum New To JavaReplies: 8Last Post: 06-08-2011, 11:27 AM -
Help Array Index out of bounds exception
By star400040 in forum New To JavaReplies: 2Last Post: 12-10-2010, 10:24 PM -
Array Index Out Of Bounds Exception
By manowar689 in forum New To JavaReplies: 3Last Post: 06-18-2010, 11:25 PM -
array Index out of Bounds exception== 0
By Allgorythm in forum New To JavaReplies: 6Last Post: 02-11-2010, 04:02 PM -
Array Index Out of Bounds Exception
By kool001 in forum New To JavaReplies: 1Last Post: 12-03-2009, 07:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks