Hello Im following the instructions in bulletpoints above fo

Hello, I\'m following the instructions in bulletpoints above for Exercise 7.1, based on the lines of Java code below, do you see any errors or code I might be missing to answer the bulletpoint instructions above?

for (int i = 7; i < 9; i++) {

   for (int j = i + 1; j < 9; j++) {

      if (the_array[i] > the_array[j]) {

      tempvar = the_array[i];

      the_array[i] = the_array[j];

      the_array[j] = tempvar;

      }
   }
}

Exercise 7.1: Array Swap During the sort of the array named the_array, two elements need to swap Using a variable named tempvar swap the values stored in slots 7 and 8 of the array You do not have to declare the array or tempvar, I will do that.

Solution

Answer: You dont need to use for loop here as per instructions. Please use below code that is enough as per instructions.Below code will swap the values from 7 and 8 locations of an array

tempvar = the_array[7];

      the_array[8] = the_array[7];

      the_array[7] = tempvar;

Hello, I\'m following the instructions in bulletpoints above for Exercise 7.1, based on the lines of Java code below, do you see any errors or code I might be m

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site