For an assignment of mine, I have to print out the contents of the following arrays. Every time I try to run the program, it gets through the first part and displays only Mercury's information. Then I get an error of
java.lang.ArrayIndexOutOfBoundsException: 1
. I know this error usually means that I am trying to call on an index that does not exist in the array
, but I do not know how to fix it.
public static void printResults(String[] name, double[] radius, double[] mass, double calcGravity[])
{
for (int i = 0; i < radius.length; i++)
{
System.out.printf("%7s %12.1f %12.1e % 12.1f", name[i], radius[i], mass[i], calcGravity[i]);
}
}