answer.
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]
2 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]2 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
____ twisted pair is the least quality twisted pair wire that should be used in a data/voice application.
xxMikexx [17]

Answer:

Category 5 (Cat 5) twisted pair is the least quality twisted pair wire that should be used.

Explanation:

The reason is as follows:

  1. Category 1 twisted pair is not suitable for transmitting data but comes in handy for telephone communications. Hence, it should not be used in a data/voice application.
  2. Category 2 twisted pair is suitable for data transmission, however, it can only transmit at 4Mbps which is very slow. Hence, it should not be used in a data/voice application.
  3. Category 3 twisted pair can transmit data with speed reaching 10Mbps which is slow for voice/data communication.
  4. Category 4 twisted pair can transmit data with speed reaching 16Mbps and is used in token ring networks. It is slow for communicating in a voice/data application.
  5. Category 5 twisted pair is the least qualified to be used in a voice/data application because it can transmit data at speeds that reach 100Mbps.

Hence, Cat 5 or Category 5 twisted pair is the least quality twisted pair that should be used in a data/voice application.

6 0
2 years ago
When performing actions between your computer and one that is infected with a virus, which of the following offers NO risk of yo
DochEvi [55]
What are the options?
3 0
2 years ago
Read 2 more answers
Multiply each element in origList with the corresponding value in offsetAmount. Print each product followed by a semicolon (no s
Pavlova-9 [17]

Answer:

Replace /* Your code goes here */  with

for(i =0; i<NUM_VALS; i++) {

    printf("%d", origList[i]*offsetAmount[i]);

printf(";");

}

Explanation:

The first line is an iteration statement iterates from 0 till the last element in origList and offsetAmount

for(i =0; i<NUM_VALS; i++) {

This line calculates and print the product of element in origList and its corresponding element in offsetAmount

    printf("%d", origList[i]*offsetAmount[i]);

This line prints a semicolon after the product has been calculated and printed

printf(";");

Iteration ends here

}

5 0
2 years ago
In which work settings would audiovisual technicians be least likely to work behind the scenes? (Select all that apply.)
snow_tiger [21]

Answer:

The correct option is;

Industrial warehouse

Explanation:

The job functions of an audiovisual technician in industrial warehouses includes;

1) Preparation and testing as well as checking equipment out and checking of equipment back in

2) Movement of equipment into trucks and vans

3) Ensuring the timely completion of tasks

4) Learn the setup and operation of equipment prior to transportation to destination sires

5) Take part in the warehouse administration.

6 0
2 years ago
The Internet is BEST described as a vast _______ connection of computer networks that also link to smaller networks
storchak [24]
Whats ur choices if there web or world try them

4 0
2 years ago
Other questions:
  • Name an analog quantity other than temperature and sound.
    14·1 answer
  • The OSHA Workplace Poster 3165 is optional for workplaces.<br> A) True<br> B) False
    13·2 answers
  • When does the narrator of "EPIC 2015" say the "road to 2015" began?
    10·2 answers
  • Given an alphabet, print all the alphabets up to and including the given alphabet.
    15·2 answers
  • There is a file "IT4983" in my home (personal) directory. I don’t know my current working directory. How can I find out the file
    11·1 answer
  • Consider the following classes:
    8·1 answer
  • C++
    8·1 answer
  • How does the discussion of “Luddites,” “Marx,” and “John Maynard Keynes” in paragraph 21 contribute to the development of the id
    7·1 answer
  • Show how the recursive multiplication algorithm computes XY, where X = 1234 and Y = 4321. Include all recursive computations.
    11·1 answer
  • How do many corporations most likely manage the health and safety of their employees and the workplace?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!