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
A circular section of material is tested. The original specimen is 200 mm long and has a diameter of 13 mm. When loaded to its p
n200080 [17]

Answer:

modulus of elasticity = 100.45 Gpa,

proportional limit = 150.68 N/mm^2.

Explanation:

We are given the following parameters or data in the question as;

=> "The original specimen = 200 mm long and has a diameter of 13 mm."

=> "When loaded to its proportional limit, the specimen elongates by 0.3 mm."

=> " The total axial load is 20 kN"

Step one: Calculate the area

Area = π/ 4 × c^2.

Area = π/ 4 × 13^2 = 132.73 mm^2.

Step two: determine the stress induced.

stress induced = load/ area= 20 × 1000/132.73 = 150.68 N/mm^2.

Step three: determine the strain rate:

The strain rate = change in length/original length = 0.3/ 200 = 0.0015.

Step four: determine the modulus of elasticity.

modulus of elasticity = stress/strain = 150.68/0.0015 = 100453.33 N/mm^2 = 100.45 Gpa.

Step five: determine the proportional limit.

proportional limit = 20 × 1000/132.73 = 150.68 N/mm^2.

7 0
3 years ago
Read 2 more answers
An electrical current of 700 A flows through a stainlesssteel cable having a diameter of 5 mm and an electricalresistance of 610
KatRina [158]

Answer:

778.4°C

Explanation:

I = 700

R = 6x10⁻⁴

we first calculate the rate of heat that is being transferred by the current

q = I²R

q = 700²(6x10⁻⁴)

= 490000x0.0006

= 294 W/M

we calculate the surface temperature

Ts = T∞ + \frac{q}{h\pi Di}

Ts = 30+\frac{294}{25*\frac{22}{7}*\frac{5}{1000}  }

Ts=30+\frac{294}{0.3928} \\

Ts =30+748.4\\Ts = 778.4

The surface temperature is therefore 778.4°C if the cable is bare

6 0
3 years ago
Identify factors that can cause a process to become out of control. Give several examples of such factors.
Oliga [24]

Answer:

Explained

Explanation:

This situation can occur because of various factors such as:

  • Gradual deterioration of lubrication and coolant.
  • change of environmental condition such as temperature, humidity, moisture, etc.
  • Change in the properties of incoming raw material
  • An increase or decrease in the temperature of the heat treating operation
  • Debris interfering with the manufacturing process.
4 0
3 years ago
Army people are good people right
Phantasy [73]

Answer: Yes army people are good people but it also depends on how you fraze that some have been in trouble before but it doesnt mean there bad people we all make mistakes

5 0
3 years ago
Thin film deposition is a process where: a)-elemental, alloy, or compound thin films are deposited onto a bulk substrate! b)-Pho
marshall27 [118]

Answer:

(A) elemental, alloy, or compound thin films are deposited on to a bulk substrate

Explanation:

In film deposition there is process of depositing of material in form of thin films whose size varies between the nano meters to micrometers onto a surface. The material can be a single element a alloy or a compound.

This technology is very useful in semiconductor industries, in solar panels in CD drives etc

so from above discussion it is clear that option (a) will be the correct answer

8 0
3 years ago
Other questions:
  • The volume at a section of a 2-lane highway is 1800 vph in each direction and the density is approximately 30 bpm. A slow moving
    10·1 answer
  • The position of a particle moving along a straight line is defined by the relation. s = t^3 – 6t^2 – 15t + 40, where s is expres
    13·1 answer
  • Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print
    10·1 answer
  • An aggregate blend is composed of 65% coarse aggregate by weight (Sp. Cr. 2.635), 36% fine aggregate (Sp. Gr. 2.710), and 5% fil
    5·1 answer
  • Which happens when a wave passes through an opening
    12·2 answers
  • Problem 3.10 One/half million parts of a certain type are to be manufactured annually on dedicated production machines that run
    7·2 answers
  • PLZZZZZ HELP
    10·2 answers
  • The current at resonance in a series L-C-R circuit is 0.2mA. If the applied voltage is 250mV at a frequency of 100 kHz and the c
    9·1 answer
  • What happens to the electrolyte, during discharging?
    9·1 answer
  • If we didn’t have the spark what could not happen?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!