Can this be done in java please 1244 Assume the following ar
Can this be done in java please 12.44
Assume the following array
3
7
1
4
9
4
8
2
7
3
9
5
4
0
5
8
Array iVals
Write a void method that receives the array iVals as a parameter; display each value in the array on a single horizontal line with each value separated by a space
Write a void method that receives the array iVals as a parameter; display each value in the row, separated by a space. Advance to the next line for output when you reach the end of the row.
Write a void method that receives the array iVals as a parameter; display each column horizontally, with each value in the column separated by a space. Advance to the next line for output when you reach the end of the column.
Using a method, calculate and display the row subtotal for each row within the method (sum of the values). Sample output, first row:
Row 1 subtotal: 15
…
Using a method, calculate and display the column subtotal for each row within the method. Sample output, first column:
Column 1 subtotal: 23
…
Using a method, calculate and return the mean of all data values in all cells; display the mean in the main() method.
| 3 | 7 | 1 | 4 |
| 9 | 4 | 8 | 2 |
| 7 | 3 | 9 | 5 |
| 4 | 0 | 5 | 8 |
Solution
Here is the code for you:
class ArrayiVals
{
//Write a void method that receives the array iVals as a parameter; display each value
//in the array on a single horizontal line with each value separated by a space
public static void horizontalDisplay(int[][] array)
{
for(int i = 0; i < array.length; i++)
for(int j = 0; j < array[i].length; j++)
System.out.print(array[i][j] + \" \");
System.out.println();
}
//Write a void method that receives the array iVals as a parameter; display each value in the
//row, separated by a space. Advance to the next line for output when you reach the end of the row.
public static void arrayDisplay(int[][] array)
{
for(int i = 0; i < array.length; i++)
{
for(int j = 0; j < array[i].length; j++)
System.out.print(array[i][j] + \" \");
System.out.println();
}
System.out.println();
}
//Write a void method that receives the array iVals as a parameter; display each column
//horizontally, with each value in the column separated by a space. Advance to the next
//line for output when you reach the end of the column.
public static void arrayTransposeDisplay(int[][] array)
{
for(int i = 0; i < array[0].length; i++)
{
for(int j = 0; j < array.length; j++)
System.out.print(array[j][i] + \" \");
System.out.println();
}
System.out.println();
}
//Using a method, calculate and display the row subtotal for each row within the method (sum of the values).
public static void rowTotals(int[][] aray)
{
for(int i = 0; i < array.length; i++)
{
int sum = 0;
for(int j = 0; j < array[i].length; j++)
sum += array[i][j];
System.out.println(\"Row \" + (i+1) + \" subtotal: \" + sum);
}
}
//Using a method, calculate and display the column subtotal for each row within the method.
public static void colTotals(int[][] aray)
{
for(int i = 0; i < array[0].length; i++)
{
int sum = 0;
for(int j = 0; j < array.length; j++)
sum += array[j][i];
System.out.println(\"Column \" + (i+1) + \" subtotal: \" + sum);
}
}
//Using a method, calculate and return the mean of all data values in all cells;
//display the mean in the main() method.
public static double meanOfArray(int[][] array)
{
double sum = 0;
int count = 0;
for(int i = 0; i < array.length; i++)
for(int j = 0; j < array[i].length; j++)
{
sum += array[i][j];
count++;
}
return sum / count;
}
}


