Homework Solution: Write a program MySelection.java that reads 3 different lists from a file, sorts them using selection sort and print the sorte…

    Write a program MySelection.java that reads 3 different lists from a file, sorts them using selection sort and print the sorted list to the screen. Use the following main function public static void main(Stringl] throws Exception String s = list + ǐ+ .txt; Rantt( Current array %d : n, i); Sustem.autupriutla(Arratestring (uxAcxax)); SartArraxlsingSelestinart (nAcrax) SustenRutRcant Sorted array %d : n, i); Syat.om.autacintia (Accaxaatoitcing(owácca))i
    Write a program MySelection.java that reads 3 different lists from a file, sorts them using selection sort and print the sorted list to the screen. Use the following main function, public static void main(String[] args)throws Exception { for (integral i = 1: i lessthanorequalto 3, i++) { String s = "list" + i + ".txt": int [] myarray = getList(s): System.out.println ("Current array %d: n", i): System.out.println (Arrays.toString (myarray)): SortArrayUsingSelectionSort (myArray): System.out.println ("Sorted array %d: n", i): System.out.println (Arrays.toString(myArray)): } }

    Expert Answer

     
    MySelection.java import java.io.File;

    Write a program MySelection.java that reads 3 contrariant inventorys from a refine, characters them using choice character and sculpture the charactered inventory to the ward. Use the subjoined deep business common static vacant deep(Stringl] throws Exception String s = inventory + ǐ+ .txt; Rantt( Current accoutre %d : n, i); Sustem.autupriutla(Arratestring (uxAcxax)); SartArraxlsingSelestinart (nAcrax) SustenRutRcant Charactered accoutre %d : n, i); Syat.om.autacintia (Accaxaatoitcing(owácca))i

    Write a program MySelection.java that reads 3 contrariant inventorys from a refine, characters them using choice character and sculpture the charactered inventory to the ward. Use the subjoined deep business, common static vacant deep(String[] args)throws Exception { coercion (all i = 1: i lessthanorequalto 3, i++) { String s = “list” + i + “.txt”: int [] myaccoutre = getList(s): System.out.println (“Current accoutre %d: n”, i): System.out.println (Arrays.toString (myarray)): CharacterArrayUsingSelectionCharacter (myArray): System.out.println (“Arranged accoutre %d: n”, i): System.out.println (Arrays.toString(myArray)): } }

    Expert Apology

     

    MySelection.java

    import java.io.File;

    import java.io.FileNotFoundException;

    import java.util.Arrays;

    import java.util.Scanner;

    common arrange MyChoice {

    common static vacant deep(String[] args) throws Exception {

    for(int i=1;i<=3;i++) {

    String s = “list”+i+”.txt”;

    int[] myAccoutre = getList(s);

    System.out.printf(“Current accoutre %d.n”, i);

    System.out.println(Arrays.toString(myArray));

    SortArrayUsingSelectionSort(myArray);

    System.out.printf(“Arranged accoutre %d.n”, i);

    System.out.println(Arrays.toString(myArray));

    }

    }

    common static vacant CharacterArrayUsingSelectionSort(int arr[]){

    coercion (int i = 0; i < arr.elongation – 1; i++)

    {

    int condemnation = i;

    coercion (int j = i + 1; j < arr.length; j++)

    if (arr[j] < arr[index])

    condemnation = j;

     

    int smallerNumber = arr[index];

    arr[index] = arr[i];

    arr[i] = smallerNumber;

    }

    }

    common static int[] getList(String refineName) throws RefineNotFoundException {

    Refine refine = novel Refine(fileName);

    Scanner review = novel Reviewner(file);

    int estimate = 0;

    while(scan.hasNextInt()) {

    count++;

    scan.nextInt();

    }

    int[] arr = novel int[count];

    Scanner review1 = novel Reviewner(file);

    estimate = 0;

    while(scan1.hasNextInt()) {

    arr[count] = review1.nextInt();

    count++;

    }

    return arr;

    }

    }

    Output:

    Current accoutre 1.
    [3, 4, 5, 6, 7, 1, 9, 8]
    Arranged accoutre 1.
    [1, 3, 4, 5, 6, 7, 8, 9]
    Current accoutre 2.
    [44, 66, 22, 11, 33, 88, 77]
    Arranged accoutre 2.
    [11, 22, 33, 44, 66, 77, 88]
    Current accoutre 3.
    [333, 555, 777, 88, 999, 111, 222]
    Arranged accoutre 3.
    [88, 111, 222, 333, 555, 777, 999]