Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I\'m following the instructions in bulletpoints above for Exercise 7.1, b

ID: 3927911 • Letter: H

Question

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.

Explanation / Answer

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;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote