68 774
Assignments Done
Successfully Done
In January 2019

Answer to Question #69432 in Java | JSP | JSF for fahad

Question #69432
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 you cannot
change the above declaration and that each task is independent of the other three:

(a) Initialize 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 (of the same magnitude)
(d) Print the contents of the locations in the array with odd-numbered index
Expert's answer

for (int i=0; i<SIZE; i++)
sample[i] = 5;

int temp = sample[0];
sample[0] = sample[SIZE-1];
sample[SIZE-1] = temp;

for (int i=0; i<SIZE; i++)
if (sample[i] < 0)
sample[i] = -sample[i];

for (int i=1; i<SIZE; i+=2)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions