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
This is used in a program to mark the beginning or ending of a statement, or separate items in a list:_____
hammer [34]

Answer:

B) Punctuation

Explanation:

Punctuation are greatly used in different programming languages for different purposes. In the Java, C++ and C# Programming languages for example, two popular punctuation marks are the comma (,) and semi-colon (;). The comma is used for separating elements of a list and arrays, while the semi-colon indicates end of an executable statement or line of code. Other popular punctuation marks used in programming are periods (dot), question marks, parenthesis angle brackets and braces each implementing a specific grammatical syntax in the language.

5 0
3 years ago
A(n) ___________ allows people at two or more locations to interact via two-way video and audio transmissions simultaneously as
nasty-shy [4]

Answer:

A(n) videoconference allows people at two or more locations to interact via two-way video and audio transmissions simultaneously as well as share documents, data, computer displays, and whiteboards.

6 0
3 years ago
Which network could NOT carry commercial traffic?
sattari [20]

ARPANET would not carry it

4 0
3 years ago
What is paragraphing in keyboarding? ​
sesenic [268]

Answer:

the pilcrow symbol is paragraphing in keyboard

5 0
4 years ago
Read 2 more answers
What is the quickest option for adding internet images to a power point presentation
Alex777 [14]

Answer:copy and paste

Explanation:

5 0
3 years ago
Other questions:
  • Which of the Arts, A/V Technology, and Communication career cluster pathways are involved with producing a product for an audien
    8·2 answers
  • Read the following code carefully and do as directed: int main() { // Initialising starting number int num = 1; int n=7 // Outer
    5·1 answer
  • Which command should you enter to configure a single port to discard inferior bpdus 200-125?
    5·1 answer
  • From the Software Engineering Code of Ethics, which clauses relate to intellectual property (check all that apply)
    15·1 answer
  • after clicking the start button on your computer screen desktop what option would you then select to examine system components y
    15·1 answer
  • Is it important for a writer to include voice and point of view in writing because...<br> Plz help
    10·1 answer
  • CORRECT ANSWER GETS BRAINLIEST
    8·2 answers
  • Most presentation programs allow you to save presentations so they can be viewed online by saving them as ____
    5·2 answers
  • Which of the following does Secure Sockets Layer (SSL) use to authenticate a user or system before encrypting a session?
    14·1 answer
  • 1. Write a 400-500 word research report about Burke High School.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!