Homework help 1.Declare a two-dimensional array of ints named grades. It should
ID: 3558919 • Letter: H
Question
Homework help
1.Declare a two-dimensional array of ints named grades. It should have 30 rows and 10 columns.
int grades [30][10]
2.Home many total elements are in the following array? double sales[6][4];
Ten total elements?
3.Write a statement that assigns the value 56893.12 to the first column of the first row of the array declared in (2).
double sales[i][j]=56893.12;
4.Write a statement that displays the contents of the last column of the last row of the array declared in (2).
double sales[6][4];
5.Declare a 2-dimensional array named settings large enough to hold the table of information below. Initialize the array with the values below:
1st row: 12,24,32,21,42
2nd row: 14,67,87,65,90
3rd row: 19,1, 24,12,8
int settings [3][1]={12,24,32,21,42
14,67,87,65,90
19,1,24,12,8}
6.Write a function called displayArray. The function should accept a 2-dimensional array as an argument and display its contents on the screen. The function should work with any of the following arrays:
int hours[5][7];
int stamps[8][7];
int autos[12][7];
int cats[50][7];
Explanation / Answer
This is the solution
a) int grades[][]=new int[30][10];
b)in the array doule sales[6][4] no of rows=6 and no. of columns=4 so total elements =6*4=24
c)sales[0][0]=56893.12
d)System.out.println("The last element is"+sales[5][3]);
e)The array must have 3 rows and 5 columns to hold the table data so the array must be
int data[][]={{12,24,32,21,42},{14,67,87,65,90},{19,1, 24,12,8}}; is the solution
f)Here is the function with comments
public void displayArray(int[][] array) {
// the length property gives the number of rows in the array and the
// number of columns are equal to 7 as known to us
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < 7; j++) {
System.out.println(array[i][j]);
}
System.out.println();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.