subject

The following sort method correctly sorts the integers in elements into ascending order. Line 1: public static void sort(int[] elements)
Line 2: {
Line 3: for (int j = 1; j < elements. length; j++)
Line 4: {
Line 5: int temp = elements[j];
Line 6: int possibleIndex = j;
Line 7: while (possibleIndex > 0 && temp < elements[possibleIndex - 1])
Line 8: {
Line 9: elements[possibleIndex] = elements[possibleIndex - 1];
Line 10: possibleIndex--;
Line 11: }
Line 12: elements[possibleIndex] = temp;
Line 13: }
Line 14: }
Consider the following three proposed changes to the code:
Change 1
Replace line 3 with:
Line 3: for (int j = elements. length - 2; j >= 0; j--)
Change 2
Replace line 7 with:
Line 7: while (possibleIndex > 0 && temp > elements[possibleIndex - 1])
Change 3
Replace line 7 with:
Line 7: while (possibleIndex < elements. length - 1 && temp < elements[possibleIndex + 1])
and replace lines 9-10 with:
Line 9: elements[possibleIndex] = elements[possibleIndex + 1];
Line 10: possibleIndex++;
Suppose that you wish to change the code so that it correctly sorts the integers in elements into descending order rather than ascending order. Which of the following best describes which combinations of the proposed changes would achieve this goal?
A) Enacting any of the three changes individually
B) Enacting changes 1 and 2 together, or enacting change 3 by itself
C) Enacting changes 1 and 3 together, or enacting change 2 by itself
D) ONLY enacting changes 1 and 2 together
E) ONLY enacting change 2 by itself

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 16:30
Primary tech skills are skills that are necessary for success in online education
Answers: 3
question
Computers and Technology, 25.06.2019 02:30
On the pie chart below, which “slice” represents 30% of the budget?
Answers: 2
question
Computers and Technology, 25.06.2019 04:00
Use the wrap text icon to modify which graphic appears in the front of layered images modify the picture effects change the way text is wrapped around an object apply wordart to the text
Answers: 1
question
Computers and Technology, 25.06.2019 10:30
Design a payroll class with the following fields: • name: a string containing the employee's name • idnumber: an int representing the employee's id number • rate: a double containing the employee's hourly pay rate • hours: an int representing the number of hours this employee has worked the class should also have the following methods: • constructor: takes the employee's name and id number as arguments • accessors: allow access to all of the fields of the payroll class • mutators: let the user assign values to the fields of the payroll class • grosspay: returns the employee's gross pay, which is calculated as the number of hours worked times the hourly pay rate. write another program that demonstrates the class by creating a payroll object, then asking the user to enter the data for an employee in the order: name, id number, rate, hours. the program should then print out a statement in the following format (for example, if you had an employee named chris jacobsen with id number 11111, who works for 5 hours at $10/hr): chris jacobsen, employee number 11111, made $50.00 in gross pay. using text forming so that the gross pay is rounded to two decimal places.
Answers: 2
You know the right answer?
The following sort method correctly sorts the integers in elements into ascending order. Line 1: pu...
Questions
question
Biology, 19.11.2020 03:30
question
Mathematics, 19.11.2020 03:30
question
Mathematics, 19.11.2020 03:30
Questions on the website: 13722367