Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the declaration/initialization statement for an integer array named hours

ID: 3573743 • Letter: W

Question

Write the declaration/initialization statement for an integer array named hours that holds the following values: 11, 22, 33 and 44. Write a statement for printing the second element value of the above declared array. Write the declaration statement for a two dimensional array named sheet that represents a table with 20 rows and 10 columns, knowing that all the elements are floating-point numbers. How many elements are there in the above declared array? Write an assignment statement to assign the value 99.99 to the last element of the above declared array. Suppose we have an array as declared below, write the necessary code 3 assign the integer values from 1 to 100 to the array elements. Consider the array above, write the necessary code to print all the array element values backward (i.e., from the last array element value backward to the first.) An array can hold multiple values under one name; therefore, an array can be used to hold the field values for a database record if all the field values are of the same data type.

Explanation / Answer

1. int hours[]={11,22,33,44};//declaration, instantiation and initialization    


2. second element will be at index 1, as array starts from index 0
   System.out.println(hours[1])

3. double[][] sheet = new double[20][10];

4. Total elements = 20*10 => 200

5.   last row = 19
   last column = 9
   sheet[19][9] = 99.99;

6. int [] a = new int[100];
   for(int i = 0; i < 100; i++)
   {
       a[i] = i+1;
   }

7.    for(int i = 99; i >= 0; i--)
   {
       System.out.println(a[i]);
   }

8. False, Only one value is possible at any index of array