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
vovangra [49]
3 years ago
7

Write a client program ClientSorting2 and in the main() method: 1. Write a modified version of the selection sort algorithm (Sel

ectionSorter()) that sorts an array of 23 strings (alphabetically) rather than one of integer values. Print the array before it is sorted in the main() method, then after it is sorted in SelectionSorter().
Computers and Technology
1 answer:
TEA [102]3 years ago
3 0

Answer:

The program in Java is as follows:

import java.util.*;

public class Main{

 public static void SelectionSorter(String[] my_array){

     System.out.print("\nAfter sort: ");

     for (int ind=0; ind < 22; ind++ ){

         int min = ind;

         for (int k=ind+1; k < 23; k++ )

         if (my_array[k].compareTo(my_array[min] ) < 0 ){ min = k;  }

         String temp = my_array[ind];

         my_array[ind] = my_array[min];

         my_array[min] = temp;    }

   for (int j=0; j < 23; j++){   System.out.print(my_array[j]+" ");}

    }

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 String [] myarray = new String [23];

 for(int i= 0;i<23;i++){ myarray[i] = input.nextLine();  }

 System.out.print("Before sort: ");

 for ( int j=0; j < 23; j++ ){        System.out.print(myarray[j]+" ");    }

 SelectionSorter(myarray);

}

}

Explanation:

This defines the function

 public static void SelectionSorter(String[] my_array){

This prints the header for After sort

     System.out.print("\nAfter sort: ");

This iterates through the array

     for (int ind=0; ind < 22; ind++ ){

This initializes the minimum index to the current index

         int min = ind;

This iterates from current index to the last index of the array

         for (int k=ind+1; k < 23; k++ )

This compares the current array element with another

         if (my_array[k].compareTo(my_array[min] ) < 0 ){ min = k;  }

If the next array element is smaller than the current, the elements are swapped

<em>          String temp = my_array[ind];</em>

<em>          my_array[ind] = my_array[min];</em>

<em>          my_array[min] = temp;    }</em>

This iterates through the sorted array and print each array element

   for (int j=0; j < 23; j++){   System.out.print(my_array[j]+" ");}

    }

The main begins here

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

This declares the array

 String [] myarray = new String [23];

This gets input for the array elements

 for(int i= 0;i<23;i++){ myarray[i] = input.nextLine();  }

This prints the header Before sort

 System.out.print("Before sort: ");

This iterates through the array elements and print them unsorted

 for ( int j=0; j < 23; j++ ){        System.out.print(myarray[j]+" ");    }

This calls the function to sort the array

 SelectionSorter(myarray);

}

}

You might be interested in
Social engineering attacks can be carried out:______.
Alik [6]
The answer most likely B NOT SURE )
3 0
3 years ago
Can anyone answer this picture?
sasho [114]

This program multiplies integer inputs A and B, by repeatedly adding B to RESULT while decrementing A.


It will work fine when either A or B is zero. If A is zero, it will branch to QUIT immediately. If B is zero, zero will be added repeatedly to the result (which also is initialized with zero).


LOOP, RESULT etc. are called labels. They translate into a memory address location of a variable or machine instruction. But it is much more readable to have them as english words while creating your program. Also, they make your program relocatable, in the sense that while writing, you don't have to decide on which physical address your program will run.

7 0
3 years ago
When researching using the internet, you should always ensure that the information you find on a website is ________.
Schach [20]

The answer is the last choice, "Credible."


Fun and entertaining websites are good for your personal time, but not for research. Persuasive websites may seem convincing, but usually persuade through emotions rather than facts. Therefore, you should make sure the information/website is credible and is supported by facts and reliable individuals.

4 0
4 years ago
Assign courseStudent's name with Smith, age with 20, and ID with 9999. Use the print member method and a separate println statem
antiseptic1488 [7]

Answer:

courseStudent.setName("Smith");

courseStudent.setAge(20);

courseStudent.setID(9999);

courseStudent.printAll();

System.out.print(", Id: " + courseStudent.getID());

Explanation:

This is the part of the code that needs to be added in order to print the output same as mentioned in the question. These lines should be added in the main method where solution is asked.

6 0
3 years ago
You wouldn't think a simple shop like Dippy Donuts would be an interesting target for hackers. But look beyond the donuts and yo
Veronika [31]

Answer:

Yes, the site can be attacked for data theft. This is done mainly through malware, which is a piece of code, and if the site is small then you can find that piece of code on your own by having a look manually through the complete code, as it can be few hundred lines of code. However, if the code length is more then you can make use of the software like the Codeguard. And that can certainly help you out considerably. Or you can buy the services of top security service providers like Sucuri.

Explanation:

Please check the answer section.

5 0
4 years ago
Other questions:
  • Microsoft Paint can be described as a digital sketch pad ?
    8·1 answer
  • Which of the following statements about relays is correct? A. A relay is a type of rheostat. B. A normally closed relay closes a
    6·2 answers
  • Which of the following has likely attended vocational school?
    10·1 answer
  • You are looking for a backup that copies only the files that have changes since the last full backup. Which of the following wil
    13·1 answer
  • Help thanks appreciate it
    12·1 answer
  • What does it mean for a design to be content driven
    12·1 answer
  • (fill in the blank) <br><br> ____ is when data is formatted, transmitted and received in a network.
    13·1 answer
  • Write a program that: Takes the list lotsOfNumbers and uses a loop to find the sum of all of the odd numbers in the list (hint:
    5·1 answer
  • Question 3 (5 points) ✔ Saved Janice is scrolling through her feed one day and notices that Abby said some awful things about Pa
    14·2 answers
  • Write getfirstroot and getsecondroot to return the first and second roots. return a domain_error is there is no first or second
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!