In: Computer Science
in java
Suppose that an array is declared and constructed as below. Each part of this problem is independent (i.e. the answer to b) should not depend on your answer to a).
int[] scores = {10, 8, 6, 4, 2, 0};
a) What is scores[1]?
b) What is scores.length?
c) What is scores[5]?
d) What array will the method call below return? Read the API carefully
Arrays.copyOfRange(scores, 2, 4)
e) What will the method call below return? Read the API very carefully.
Arrays.sort(scores);
Arrays.binarySearch(scores, 7);
a)sores[1]=8
Reason:In arrays index number starting from 0
______________
b)scores.length=6
______________
c)scores[5]=0
______________
d) Arrays.copyOfRange(scores, 2, 4) this will return an integer array which contains elements {6,4}
Reason:here starting position is 2 (inclusive)
Ending position is 4 (exclusive)
________________
e) Arrays.sort(scores); this will sort the elements in the array in the ascending order.
Int scores[] ={0,2,4,6,8,10};
_____________
f) Arrays.binarySearch(scores, 7);
here we are going to search the value 7 in the array scores.As we didn’t find the value 7 in the array score which returns an insertion point
Here the insertion point is point at which we can insert the value.
Here we have to insert the 7 value after the value 6 in the array(On sorted array in ascending order).so its(element 7) index position is 4
So it returns -insertionpoint -1=-4-1=-5
______________