Question: JAVA please// I have already done code but I need help to fix the errors I am getting. please repond will a full code to

JAVA please// I have already done code but I need help to fix the errors I am getting. please repond will a full code to input in. I will attach a photo of my errors as well.Thank you!
JAVA please// I have already done code but I need help to
fix the errors I am getting. please repond will a full code
to input in. I will attach a photo of my errors as
well.Thank you! 17.12 LAB: Insertion sort The program has four steps: 1.
Read the size of an integer array, followed by the elernents of
the array (no duplicates) 2. Output the array. 3. Perform an insertion
sort on the array. 4. Output the number of comparisons and swaps

17.12 LAB: Insertion sort The program has four steps: 1. Read the size of an integer array, followed by the elernents of the array (no duplicates) 2. Output the array. 3. Perform an insertion sort on the array. 4. Output the number of comparisons and swaps performed. main0 nerforms steps 1 and 2 Implement step 3 based on the insertion sort algorithm in the book. Modify insertionsorte to - Count the number of comparisons performed - Count the number of swaps performed. - Output the array duning each iteration of the outside loop. Complete maing to perform step 4 a according to the format shown in the example below. Hints: in order to count comporisons and swaps, modily the while loop in insertionsort0. Use static variables for camparisons and awss The program provides three helper methodn: 1f Hhend and rekum an ortay of intedeta. 11 Thin tirat intibget read in number of integeca that toliok. ine 11 repaklurin 0 1/ Read and rotuzn an array of integers. I/ The first integer read is number of integers that follow. int [1 readiums ( ) 1/ print the numbers in the array, separated by spaces /1. (No space or newline before the IIrst number or after the last. void printkioms (int {1 nums) If Exchange nums {j} and nums {k]. void swap (int (1 nums, int j, int k). Ex. When the input is: 6321=598 - the output is: 3211212322221133335555559599986988898 ecimparioons 7 annegi 4 Load default template... import java. util. Scanner; public class LabProgram \{ public static int readNums ) \{ Scanner sc= new Scanner(System, in); int n; nusc.nextInt(); int nums ]= new int [n]; for (int i=0;i= \& 8 nums [j]> temp) \{ flag=true; nums [j+1]-nums [j]; swapst+; comparison+; jj1; int comparison=0; int swaps =0; int n= nums. length; for (int i=1;i=0 \& & nums [j]> temp) \{ flag=true; nums [j+1]= nums [j]; swapst+; comparison+t; j=j1; \}) if (lflog) f comparison+t; b nums [j+1]-temp; for ( int i1=0; i1 enums, length; i1++) f System,out.print(nums [i1]+" "); 3 System.out.println(); \} comparisonit; 3 System, out.println("comparisons: "+comparisont" swaps: "+swaps); public static void main(String ] args) \& int nums -readNums (); printNums(nums); System.out, printlin( ; System,out.println(; swap(nums); 3 Output is nearly correct, but whitespace differs. See highlights below. Special character iegend 97654321comparisons:swaps:7976543228669765435559765444449765333339762222229711111119 79654321 67954321 56794321 Expected output 4321comparisons:swaps:543228286543765497653976229711194

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!