OK this is an assignment due at 11:30pm tonight. I have very little time left. I am getting this when I try to run it.
java.lang.ArrayIndexOutOfBoundsException: 3
at ArrayOps.getTotal<ArrayOps.java:55>
at ArrayOps.main<ArrayOps.java:20>
The debug is not picking anything up so I don't know what to change. I have tried everything I know to try. I haven't been able to talk to my professor but once this week.
The spacing and what not gets unorganized when you paste it so ignore anything that is over too far or vise versa.
java.lang.ArrayIndexOutOfBoundsException: 3
at ArrayOps.getTotal<ArrayOps.java:55>
at ArrayOps.main<ArrayOps.java:20>
The debug is not picking anything up so I don't know what to change. I have tried everything I know to try. I haven't been able to talk to my professor but once this week.
The spacing and what not gets unorganized when you paste it so ignore anything that is over too far or vise versa.
private static int getTotal(int[][] numbers)
{
int total = 0; //acummulator
for (int row = 0; row < numbers.length; row++)
{
for (int col = 0; col < numbers.length; col++)
total += numbers[row][col];
}
return total;
}
/* The following method is to return the average of the numbers int the
array as the arrayAverage variable
*/
private static double getAverage(int[][] numbers)
{
double average;
int total = 0; //acummulator
for (int row = 0; row < numbers.length; row++)
{
for (int col = 0; col < numbers.length; col++)
{
total += numbers[row][col];
}
}
average = total / numbers.length;
return average;
}
/* The following method is to get and display the total for one row in the
numbers array as rowTotal
*/
private static int getRowTotal(int[][] numbers)
{
int rowTotal = 0; //accumulator
for (int row = 0; row < numbers.length; row++)
{
for (int col = 0; col < numbers[row].length; col++)
rowTotal += numbers[row][col];
System.out.println("The total for row " + row + " is " + rowTotal);
}
return rowTotal;
}
/* The following method is to get and display the total for one column in the
numbers array as colTotal
*/
private static int getColumnTotal(int[][] numbers)
{
int colTotal = 0; //accumulator
for (int col = 0; col < numbers[0].length; col++)
{
for (int row = 0; row < numbers.length; row++)
colTotal += numbers[row][col];
System.out.println("The total for column " + col + " is " + colTotal);
}
return colTotal;
}
/* The following method is to get and the highest number in a given row
in the numbers arrat as rowHighest
*/
private static int getHighestInRow(int[][] numbers)
{
//loop for getting highest number
int highest = numbers[0][0];
for (int row = 0; row < numbers[row].length; row++)
{
if (numbers[row][0] >= highest)
highest = numbers[row][0];
System.out.println("The highest number in row " + row + " is " + highest);
}
return highest;
}
/* The following method is to return the lowest number in a given row
in the numbers arrat as rowLowest
*/
private static int getLowestInRow(int[][] numbers)
{
int lowest = numbers[0][0];
for (int row = 0; row < numbers[row].length; row++)
{
if (numbers[row][0] <= lowest)
lowest = numbers[row][0];
System.out.println("The lowest number in row " + row + " is " + lowest);
}
return lowest;
}
}