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
mihalych1998 [28]
4 years ago
7

Write a void method selectionSortDescendTrace() that takes an integer array, and sorts the array into descending order. The meth

od 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 main() to read in a list of up to 10 positive integers (ending in -1) and then call the selectionSortDescendTrace() 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
Computers and Technology
1 answer:
DENIUS [597]4 years ago
6 0

Answer:

  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3. public class Main {
  4.    public static void main(String[] args) {
  5.        int numArr [] = new int[10];
  6.        Scanner input = new Scanner(System.in);
  7.        System.out.print("Input number: ");
  8.        int num = input.nextInt();
  9.        int i = 0;
  10.        while(num != -1){
  11.            numArr[i] = num;
  12.            i++;
  13.            System.out.print("Input number: ");
  14.            num = input.nextInt();
  15.        }
  16.        selectionSortDescendTrace(numArr);
  17.    }
  18.    public static void selectionSortDescendTrace(int [] arr){
  19.        for(int i =0 ; i < arr.length - 1; i++){
  20.            int largest = arr[i];
  21.            int largeIndex = i;
  22.            for(int j= i + 1; j < arr.length; j++ ){
  23.                if(arr[j] > largest){
  24.                    largest = arr[j];
  25.                    largeIndex = j;
  26.                }
  27.            }
  28.            int temp = arr[i];
  29.            arr[i] = arr[largeIndex];
  30.            arr[largeIndex] = temp;
  31.            System.out.println(Arrays.toString(arr));
  32.        }
  33.    }
  34. }

Explanation:

The solution code is written in Java.

First, we work on the selectionSortDescendTrace method that takes one input array (Line 21). In the method, we create a nested loops. In the outer loop, we set the current element indexed by i as the largest value and use another variable largeIndex to track the index of largest value (Line 23 -24).

We create inner loop to traverse through the subsequent number after current index-i and compared each of the element by the current largest value (Line 26 - 30). If any of the subsequent element is larger than the current largest value, set the element as largest value and update the largeIndex accordingly (Line 27 - 29).

After completion of inner loop, we swap the position of the current found largest number with the element indexed by current i (Line 33 - 35). Print the partially sorted array (Line 36).    

You might be interested in
What is the difference between paper size and page margins in Word?
sergij07 [2.7K]

Answer:

Paper size refers to the size of the paper you will be printing your document on, while page margins refer to the outside area of a page that can be made bigger or smaller to fit content.

Launch the Page Setup dialog box from the Page Setup group; in the Margins section, enter the page margin values and click OK.

All the statements are correct.

Right-click and add to dictionary

Type the words onto the first page of the document, and click on the Header button to repeat it on all of the other pages

pictures shapes and clipart

none of the above

Explanation:

7 0
3 years ago
If you have related data stored in multiple tables, create a(n) ________ to produce a pivottable on the combined data.
vladimir1956 [14]
If you have related data stored in multiple tables, create a Data model to<span> produce a pivot table on the combined data.
In computer term, data model refers to how each data are connected to one another and how those connections are being processed within the Sysyem</span>
3 0
4 years ago
What view and zoom setting do you need for true WYSIWYG display? Why?
gayaneshka [121]
I'm not sure. Can you be more specific?
7 0
4 years ago
What is the difference between keywords and identifiers in c++ ?
prohojiy [21]
Keywords are the reserved words of a language.Identifiers are the user defined names of variable, function and labels. Hope that this helped
3 0
3 years ago
Companies increasingly want to allow employees to share files directly without having to maintain servers to provide FTP access.
jeyben [28]

Answer:

The answer is "use P2P method".

Explanation:

In Corporation are starting to regard P2P is a method, which enabling workers to transfer files directly, reducing the expenses and construction connected with a central network.

  • It allows corporations to make the use of often latent resources on both the computer for each worker.
  • It will also be forced to control access to data to protect the privacy and sensitive materials, and will also be able to encrypt files by code.

5 0
3 years ago
Other questions:
  • With the help of what memory a computer can read as well as write or modify data
    14·2 answers
  • Main characteristic of open source software<br> ?
    7·1 answer
  • Consider a router that interconnects three subnets: subnet 1, subnet 2, and subnet 3. suppose all of the interfaces in each of t
    11·2 answers
  • The _______________ is a priority-ordered list of the other carrier networks and frequencies it should search for when it cannot
    6·1 answer
  • Select the guidelines you should follow when creating a resume
    12·2 answers
  • What is the grooming process as it relates to online predators?
    12·2 answers
  • You can divide the code for an application into logical parts by moving some of the code from the main() method to other _______
    8·1 answer
  • If an engineer wants to verify changes that she has been making on a router, which commands will allow her to check the routers
    15·1 answer
  • How do you add verticse in edit mode blender
    5·1 answer
  • Many universities form tight-knit alumni networks, causing the alumni to continue to use each other as a resource for career pla
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!