63 195
Assignments Done
99,3%
Successfully Done
In July 2018

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
Answers:

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

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

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

d)
for (int i=1; i<SIZE; i+=2)
System.out.println(sample[i]);


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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions