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
mixas84 [53]
3 years ago
10

[10] Create a program called SelectionSort.java that implements the Selection Sort algorithm (The Art of Computer Programming -

Donald Knuth). The algorithm is as follows: The program should be able to do the following: accepts one command line parameter. The parameter specifies the path to a text file containing the integers to be sorted. The structure of the file is as follows: There will be multiple lines in the file (number of lines unknown). Each line will contain multiple integers, separated by a single whitespace. reads the integers from the text file in part a into an array of integers. sort the integers in ascending order, and then prints out a sorted version of these integers, one per line. The implementation should follow the given the pseudo code/algorithm description.
Engineering
1 answer:
Alex787 [66]3 years ago
8 0

Answer:

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Scanner;

public class SelectionSort {

  public static void main(String[] args) throws FileNotFoundException {

      //For array

      ArrayList<Integer>array=new ArrayList<Integer>();

      //If argument found

      if(args.length>=1) {

          //File path

          Scanner sc=new Scanner(new File(args[0]));

          //Loop until end

          while(sc.hasNextLine()) {

              //Read each line and add into array

              String[] temp=sc.nextLine().split(" ");

              for(int i=0;i<temp.length;i++) {

                  array.add(Integer.parseInt(temp[i]));

              }

          }

          //Display array

          System.out.println("Display array: ");

          printArray(array);

          System.out.println("\nDisplay array after sort: ");

          sortArray(array);

          printArray(array);

      }

      //If argument not found

      else {

          System.out.println("Argument not found!!!");

      }

  }

  //Method to print array

  public static void printArray(ArrayList<Integer>array) {

      for(int i=0;i<array.size();i++) {

          System.out.println(array.get(i));

      }

  }

  //Method to sort array using straight selection sort

  public static void sortArray(ArrayList<Integer>array) {

      //Step1

      for(int j=array.size()-1;j>=1;j--) {

          int max=array.get(j);

          int index=j;

          //Step2

          for(int k=j;k>=0;k--) {

              if(max<array.get(k)) {

                  max=array.get(k);

                  index=k;

              }

          }

          //Step3

          array.set(index,array.get(j));

          array.set(j,max);

      }

  }

}

Explanation:

You might be interested in
Which of the following describes fibers? a)- Single crystals with extremely large length-to-diameter ratios. b)- Polycrystalline
ElenaW [278]

Answer:

b)Poly crystalline and amorphous materials with small diameter

Explanation:

Fibers have high length to diameter ratio and also have high strength.Generally length of fibers is very high and diameter is very low as compare to length.

Mostly fibers is used to transfer data from one place to another place with help of  fiber optical cables.Fiber optic cables is used in telecommunication.In these cables data covert in to the electric single and reach at define location and after data is decode and covert from electric single in to original data.

Fibers poly crystalline and amorphous materials with small diameter.

6 0
3 years ago
Conduct online research and write a short report on the origin and evolution of the meter as a measurement standard. Discuss how
valina [46]

Answer:

People have come up with all sorts of inventive ways of measuring length. The most intuitive are right at our fingertips. That is, they are based upon the human body: the foot, the hand, the fingers or the length of an arm or a stride.

In ancient Mesopotamia and Egypt, one of the first standard measures of length used was the cubit. In Egypt, the royal cubit, which was used to build the most important structures, was based on the length of the pharaoh’s arm from elbow to the end of the middle finger plus the span of his hand. Because of its great importance, the royal cubit was standardized using rods made from granite. These granite cubits were further subdivided into shorter lengths reminiscent of centimeters and millimeters.

piece of black rock with white Egyptian markings

Fragment of a Cubit Measuring Rod

Credit: Gift of Dr. and Mrs. Thomas H. Foulds, 1925

Later length measurements used by the Romans (who had taken them from the Greeks, who had taken them from the Babylonians and Egyptians) and passed on into Europe generally were based on the length of the human foot or walking and multiples and subdivisions of that. For example, the pace—one left step plus one right step—is approximately a meter or yard. (On the other hand, the yard did not derive from a pace but from, among other things, the length of King Henry I of England’s outstretched arm.) Mille passus in Latin, or 1,000 paces, is where the English word “mile” comes from.

And thus, the meter has and likely will remain so elegantly defined in these terms for the foreseeable future.

Explanation:

is this short enough

5 0
2 years ago
What are the philological elements of interior design most like?
sp2606 [1]

Answer:

Ea public address glven via the intercom system of a large buildingxplanation:

7 0
2 years ago
Steam at 1 MPa, 300 C flows through a 30 cm diameter pipe with an average velocity of 10 m/s. The mass flow rate of this steam i
stealth61 [152]

Answer:

\dot m = 2.74 kg/s

Explanation:

given data:

pressure 1 MPa

diameter of pipe  =  30 cm

average velocity = 10 m/s

area of pipe= \frac[\pi}{4}d^2

                 = \frac{\pi}{4} 0.3^2

A = 0.070 m2

WE KNOW THAT mass flow rate is given as

\dot m = \rho A v

for pressure 1 MPa, the density of steam is = 4.068 kg/m3

therefore we have

\dot m = 4.068 * 0.070* 10

\dot m = 2.74 kg/s

7 0
3 years ago
A large particle composite consisting of tungsten particles within a copper matrix is to be prepared. If the volume fractions of
OverLord2011 [107]

Answer:

Upper bounds 22.07 GPa

Lower bounds 17.59 GPa

Explanation:

Calculation to estimate the upper and lower bounds of the modulus of this composite.

First step is to calculate the maximum modulus for the combined material using this formula

Modulus of Elasticity for mixture

E= EcuVcu+EwVw

Let pug in the formula

E =( 110 x 0.40)+ (407 x 0.60)

E=44+244.2 GPa

E=288.2GPa

Second step is to calculate the combined specific gravity using this formula

p= pcuVcu+pwTw

Let plug in the formula

p = (19.3 x 0.40) + (8.9 x 0.60)

p=7.72+5.34

p=13.06

Now let calculate the UPPER BOUNDS and the LOWER BOUNDS of the Specific stiffness

UPPER BOUNDS

Using this formula

Upper bounds=E/p

Let plug in the formula

Upper bounds=288.2/13.06

Upper bounds=22.07 GPa

LOWER BOUNDS

Using this formula

Lower bounds=EcuVcu/pcu+EwVw/pw

Let plug in the formula

Lower bounds =( 110 x 0.40)/8.9+ (407 x 0.60)/19.3

Lower bounds=(44/8.9)+(244.2/19.3)

Lower bounds=4.94+12.65

Lower bounds=17.59 GPa

Therefore the Estimated upper and lower bounds of the modulus of this composite will be:

Upper bounds 22.07 GPa

Lower bounds 17.59 GPa

7 0
2 years ago
Other questions:
  • 7 Single-use earplugs require a professional fitting before they can be used.
    10·2 answers
  • For a steel alloy it has been determined that a carburizing heat treatment of 7 hour duration will raise the carbon concentratio
    12·1 answer
  • You are given a partial implementation of one header file, GildedRose.hpp. Item is a class that holds the information for each i
    6·1 answer
  • Two kilograms of air within a piston–cylinder assembly executes a Carnot power cycle with maximum and minimum temperatures of 80
    5·2 answers
  • Which process made making copies of technical drawings easier?
    8·1 answer
  • You need to lower your lift onto the mechanical load-holding devices to provide structural support before working under the lift
    12·1 answer
  • What is the name of the part of the expressway where cars can both enter and exit?
    15·1 answer
  • A 20cm-long rod with a diameter of 0.250 cm is loaded with a 5000 N weight. If the diameter of the bar is 0.490 at this load, de
    7·1 answer
  • Which pipe for water is best for construction?
    6·1 answer
  • Technician a says that personal protective equipment (ppe) does not include clothing. technician b says that the ppe used should
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!