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
What happens to the duty cycle for a GMAW Gun when 75Ar/25COzgas
skad [1K]

So what happens is the host will not kill the y no se que hacer para no one can see it in

6 0
2 years ago
Who developed the process of blueprinting?
VikaD [51]
Answer: C.) John Herschel
3 0
3 years ago
A smooth sphere with a diameter of 6 inches and a density of 493 lbm/ft^3 falls at terminal speed through sea water (S.G.=1.0027
Pachacha [2.7K]

Given:

diameter of sphere, d = 6 inches

radius of sphere, r = \frac{d}{2} = 3 inches

density,  \rho} = 493 lbm/ ft^{3}

S.G = 1.0027

g = 9.8 m/ m^{2} = 386.22 inch/ s^{2}

Solution:

Using the formula for terminal velocity,

v_{T} = \sqrt{\frac{2V\rho  g}{A \rho C_{d}}}              (1)

(Since, m = V\times \rho)

where,

V = volume of sphere

C_{d} = drag coefficient

Now,

Surface area of sphere, A = 4\pi r^{2}

Volume of sphere, V = \frac{4}{3} \pi r^{3}

Using the above formulae in eqn (1):

v_{T} = \sqrt{\frac{2\times \frac{4}{3} \pir^{3}\rho  g}{4\pi r^{2} \rho C_{d}}}

v_{T} = \sqrt{\frac{2gr}{3C_{d}}}  

v_{T} = \sqrt{\frac{2\times 386.22\times 3}{3C_{d}}}

Therefore, terminal velcity is given by:

v_{T} = \frac{27.79}{\sqrt{C_d}} inch/sec

3 0
3 years ago
Travel Time Problem: Compute the time of concentration using the Velocity, Sheet Flow Method for Non-Mountainous Orange County a
Vaselesa [24]

Answer:

Total time taken = 0.769 hour

Explanation:

using the velocity method

for sheet flow ;

Tt = \frac{0.007(nl)^{0.8} }{(Pl)^{5}s^{0.4}  }  

Tt = travel time

n = manning CaH

Pl = 25years

L = how length ( ft )

s = slope

For Location ( 1 )

s = 0.045

L = 1000 ft

n = 0.06 ( from manning's coefficient table )

Tt1 = 0.128 hour

For Location ( 2 )

s = 2.5 %

L= 750

n = 0.13

Tt2 = 0.239 hour

For Location ( 3 )

s = 1.5%

L = 500 ft

n = 0.15

Tt3 = 0.237  hour

For Location (4)

s = 0.5 %

L = 250 ft

n = 0.011

Tt4 = 0.165 hour

hence the Total time taken = Tt1 + Tt2 + Tt3 + Tt4

                                              = 0.128 + 0.239 + 0.237 + 0.165 = 0.769 hour

5 0
3 years ago
Even though the content of many alcohol blends doesn’t affect engine drive ability using gasoline with alcohol in warm weather m
Alchen [17]
Even though the content of many alcohol blends doesn't affect engine driveability, using gasoline with alcohol in warm weather may cause: decrease in fuel economy.

Mark brainliest
s
3 0
2 years ago
Other questions:
  • For problems 1 and 2, six luminaires, similar to Style E used in the Commercial Building, are to be installed in a room that is
    13·1 answer
  • What are the units or dimensions of the shear rate dv/dy (English units)? Then, what are the dimensions of the shear stress τ= μ
    14·1 answer
  • Cho biết tác dụng chung của các hệ giằng khung ngang nhà công nghiệp nhẹ 1 tầng 1 nhịp.
    13·1 answer
  • What is the volume of the rectangular prism shown.
    9·1 answer
  • The cylinder C is being lifted using the cable and pulley system shown.
    8·1 answer
  • Select the correct answer.
    11·1 answer
  • On aircraft equipped with fuel pumps, when is the auxiliary electric driven pump used?.
    15·1 answer
  • Find E[x] when x is sum of two fair dice?
    12·1 answer
  • Which pipe for water is best for construction?
    6·1 answer
  • A wheel spins at a constant angular speed of 24rad/s.How many revolutions will the dosk go through in 5minutes?​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!