1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
marysya [2.9K]
3 years ago
11

Descending selection sort with output during execution Write a void method selection SortDescend Trace() that takes an integer a

rray, and sorts the array into descending order. The method should use nested loops and output the array after each iteration of the outer loop, thus outputting the array N-1 times (where N is the size). Complete the main() to read in a list of up to 10 positive integers (ending in -1) and then call the selection SortDescendTrace() method. If the input is: 20 10 30 40 -1 then the output is: 40 10 30 20 40 30 10 20 40 30 20 10 LAB ACTIVITY 7.10.1: LAB: Descending selection sort with output during execution 0/10 DescendingOrder.java
import java.util.Scanner;

public class DescendingOrder {
// TODO: Write a void method selectionSortDescendTrace() that takes
// an integer array and the number of elements in the array as arguments,
// and sorts the array into descending order.
public static void selectionSortDescendTrace(int [] numbers, int numElements) {

}


public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);

int input, i = 0;
int numElements = 0;
int [] numbers = new int[10];

// TODO: Read in a list of up to 10 positive integers; stop when
// -1 is read. Then call selectionSortDescendTrace() method.

}
}
Computers and Technology
1 answer:
STatiana [176]3 years ago
8 0

Answer:

  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3. public class DescendingOrder {
  4.    // TODO: Write a void method selectionSortDescendTrace() that takes
  5. // an integer array and the number of elements in the array as arguments,
  6. // and sorts the array into descending order.
  7.    public static void selectionSortDescendTrace(int [] numbers, int numElements) {
  8.        for(int i = 0; i < numbers.length-1; i++){
  9.            int currentMax = numbers[i];
  10.            int index = i;
  11.            for(int j = i + 1; j < numbers.length; j++){
  12.                if(numbers[j] > currentMax){
  13.                    currentMax = numbers[j];
  14.                    index = j;
  15.                }
  16.            }
  17.            int temp = numbers[i];
  18.            numbers[i] = numbers[index];
  19.            numbers[index] = temp;
  20.            System.out.println(Arrays.toString(numbers));
  21.        }
  22.    }
  23.    public static void main(String[] args) {
  24.        Scanner scnr = new Scanner(System.in);
  25.        int input, i = 0;
  26.        int numElements = 0;
  27.        int [] numbers = new int[10];
  28. // TODO: Read in a list of up to 10 positive integers; stop when
  29. // -1 is read. Then call selectionSortDescendTrace() method.
  30.        do{
  31.            input = scnr.nextInt();
  32.            if(input != -1){
  33.                numbers[i] = input;
  34.                i++;
  35.                numElements++;
  36.            }
  37.        }while(input != -1);
  38.        selectionSortDescendTrace(numbers, numElements);
  39.    }
  40. }

Explanation:

Firstly, create a do while loop to repeatedly to prompt user for number (Line 38 - 46).

Next, proceed to work on selectionSortDescendTrace method. Create a nested loop to implement selection sort logic. In outer loop, create variable currentMax and index, to track the maximum number and position of the maximum number for each iteration (Line 11 - 12). In inner loop, a current element value from array will be checked against the subsequent elements in array to identify the maximum value of that iteration (Line 13 - 17). Upon exist from the inner loop, the currentMax is swapped with the current array element indexed by i (Line 20 -21).

Print the array to console for every outer loop iteration (Line 24).

You might be interested in
What is the purpose of citations?
Elina [12.6K]

Answer: Citiations areto show where you got information from.

Explanation:

6 0
4 years ago
Select the correct answer.
VARVARA [1.3K]

Answer:

D

Explanation:

It is D

Select the correct answer.

Identify the correct CSS syntax to link an external style sheet.

6 0
3 years ago
What is the term given to the controls that let you interact with an operating system?
Sophie [7]
Inputs are the contols that let you interact with an operating system.
4 0
4 years ago
Suppose that a database modification results in the execution of a trigger but that trigger generates another modification that
zhenek [66]

Answer:

The database can detect only system-defined events.

Explanation:

A trigger is like a stored procedure that Oracle Database invokes automatically whenever a specified event occurs.trigger is like a stored procedure that Oracle Database invokes automatically whenever a specified event occurs.

Both triggers and constraints can constrain data input, but they differ significantly.

A constraint applies to both existing and new data. For example, if a database column has a NOT NULL constraint, then its existing data is NOT NULL and no DML statement can violate the NOT NULL constraint.

A trigger applies only to new data. For example, a trigger can prevent a DML statement from inserting a NULL value into a database column, but the column might contain NULL values that were inserted into the column before the trigger was defined or while the trigger was disabled

5 0
4 years ago
Describe the difference between information poor and information rich society?​
Nadya [2.5K]

Answer:

The “Information poor” are consumers who use traditional mass media information such as television, DVDs, radios and magazines. ... On the opposite “information rich” stands for a new elite within the information society.

7 0
3 years ago
Read 2 more answers
Other questions:
  • 125 • 12² what is the answer?<br>- 124​
    6·1 answer
  • To decrease the size of text so it will fit into a text box without overflowing, select the
    14·2 answers
  • Technician A says copper has a low resistance. Technician B says the length of wire doesn't affect resistance. Who is correct?
    11·1 answer
  • Which of the following protocols is used to unsure secure transmissions on port 443?A. HTTPSB. TelnetC. SFTPD. SHTTP
    6·1 answer
  • What is an advantage of using a meta-search engine?
    14·1 answer
  • 14. What is the simplest way to permanently get rid of an unwanted file?
    9·1 answer
  • What is the minimum internal temperature that the chicken must reach?
    11·1 answer
  • Consider the classes below: public class TestA { public static void main(String[] args) { int x = 2; int y = 20 int counter = 0;
    8·1 answer
  • What limited the possibilities of game development from a technical viewpoint?
    7·1 answer
  • Tell me the errors please
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!