Suppose that “final” integer SIZE has been properly declared and initialized, and
that an array named sample has been declared as follows:
int [] sample = new int [SIZE];
Write one or more Java statements to perform the following. Note that each task is independent of the other three:
(a) Set all array elements to the value 5.
(b) “Swap” the first value in the array with the last value in the array
(c) Change any negative values to positive values (with the same magnitude)
(d) Print the contents of the “odd-numbered” locations in the array, that is the items at array index 1, 3, 5, ... etc.Attachments
i=0;i<sample.length;i++)
{
sample[i]=5;
}
/*?Swap? the first value in the array with the last value in the array*/
int temp=sample[0];
sample[0]=sample[sample.length-1];
sample[sample.length-1]=temp;
/*Change any negative values to positive values (with the same magnitude)*/
for(int i=0;i<sample.length;i++)