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
What are the Technical Skills do Penetration Testers need to have?
Alla [95]

1. Tester should understand the vulnerability of the system because by this skill it should be able to secure the system for the parts where the attacks can be done.

2. Understand the web technologies and communication techniques of them because the two way communication understanding is one of the most important skill a tester should have so that he/she should have a proper image of what the system doing and how it is doing it.

3. Ability yo code scripts and most importantly understand them because while testing there are many script code to be read and understand for any bug or error the system is facing.

5 0
3 years ago
Type the correct answer in the box. Spell all words correctly.
allsm [11]

Answer:

Ground Antennas

Explanation:

I got it right on my test

5 0
3 years ago
True / False<br> An instruction’s opcode generally indicates the number and type of its operands.
liq [111]

Answer:

True

Explanation:

An opcode is the part of instruction which specifies the operation to be performed by the instruction.

In general, the opcode also provides information about the number and type of operands.

For example, let us consider the MIPS instructions for addition.

  • ADD reg_dest, reg_src1, reg_src2

This instruction adds the contents of registers reg_src1 and reg_src2 and stores the result in reg_dest.

  • Whereas, ADDI reg_src, reg_dest, value

This instruction adds the value to the content of reg_src and stores the result in reg_dest.

As we can see the opcode type indicates the operand type, number and semantics.

7 0
3 years ago
Explain the integer and float datatypes with example.<br><br>​
Leno4ka [110]

Answer:

integers are natural numbers like 1,2,3,.....

Float data types are those that are in the form of decimals like 1.5, 2.33. 0.75

6 0
3 years ago
What might happen if you haven't decided on a course of action when you're within 4-6 seconds of the intersection?
Delicious77 [7]
You Could Cause An Accident To Happen.
7 0
4 years ago
Other questions:
  • You’ve been hired to help with installing cable at a new office building for the local branch of the Social Security Administrat
    14·1 answer
  • What most distinguishes projects with a strong need for computer animation from projects without such a strong need?
    8·1 answer
  • _____, which are generated by web server software, record a user's actions on a web site. viruses log files junk e-mails worms
    7·1 answer
  • What is the first thing you should do before constructing a window in the IDE?
    14·1 answer
  • again assume that each of the resistors in the circuit shown above has a resistance value of 100k(question in the picture above)
    9·1 answer
  • Given a String variable named line1, write a sequence of statements that use a Scanner to read the first line of a file named "p
    7·1 answer
  • What is the name of the time delay in a CPU caused by differences between the speed o CPU, the system bus, and memory circuits?
    10·1 answer
  • Https://meetme.bit.nl/OfficialTrapstarz Join yall its my birthday
    13·2 answers
  • :(.
    5·2 answers
  • Some programmers include scroll bars, title bars, buttons, and menus in a program simply by adding them to a layout through a pr
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!