.Assume that an ArrayList named salarySteps whose elements are of type Integer and that has exactly five elements has already been declared and has been assigned values.

Write a single statement to assign the value 30000 to the first element of this array.

14.Assume that an ArrayList of Integers named salarySteps has been declared and initialized with some initial values.

Write a statement that assigns the value 160000 to the last element of the ArrayList salarySteps.

15.Assume that an ArrayList of Integers named a has been declared with 12 elements. The integer variable k holds a value between 0 and 6. Assign 15 to the array element whose index is k.

16.Assume that an ArrayList of Integers named a that contains exactly five elements has been declared and initialized. In addition, an int variable j has also been declared and initialized to a value somewhere between 0 and 3.

Write a single statement that assigns a new value to element of the ArrrayList indexed by j. This new value should be equal to twice the value stored in the next element of the ArrayList (i.e. the element indexed by j+1).

Respuesta :

Answer:

  • salarySteps[0] = 30000;    
  • salarySteps[4] = 160000;
  • a[k] = 15;
  • a[j] = a[j+1] * 2;

Explanation:

In the first statement, salarySteps is an ArrayList. Total elements in the list are 5. To assign the value 30000 to first element of the array, 0 is the index which is the position of that array element as the array starts from 0 index. 0 points to the starting element of the array salarySteps.

In the second statement 160000 is assigned to the last element of the array names salarySteps. As the total elements are 5, so the array index starts from 0 to 4. As the value is to be assigned to the last element of array list so this means that the index is 4.

In the third statement the the name of the Array list is a and it has 12 elements.  The k-th element of this array list has to be assigned the value of 15. So the statement is a[k] = 15 where k is the index and 15 is the value assigned to the k-th index of array list a.

In the fourth statement new value is to be assigned to the element of array list a which has an index j. The new value should be equal to twice the value in the next element of array list. This next value is pointed by the index j+1. So the statement is a[j] = a[j+1] * 2; where a is the array list j is the index of the array element which is equal to twice the value (multiplied by 2) stored in the next element to the index position j i.e. j+1.