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 opposed rolls from a finish, orders them using segregation order and stereotype the ordered roll to the ward. Use the restraintthcoming ocean capacity national static unfilled ocean(Stringl] throws Exception String s = roll + ǐ+ .txt; Rantt( Current draw-up %d : n, i); Sustem.autupriutla(Arratestring (uxAcxax)); SartArraxlsingSelestinart (nAcrax) SustenRutRcant Ordered draw-up %d : n, i); Syat.om.autacintia (Accaxaatoitcing(owácca))i

    Write a program MySelection.java that reads 3 opposed rolls from a finish, orders them using segregation order and stereotype the ordered roll to the ward. Use the restraintthcoming ocean capacity, national static unfilled ocean(String[] args)throws Exception { restraint (integral i = 1: i lessthanorequalto 3, i++) { String s = “list” + i + “.txt”: int [] mydraw-up = getList(s): System.out.println (“Current draw-up %d: n”, i): System.out.println (Arrays.toString (myarray)): OrderArrayUsingSelectionOrder (myArray): System.out.println (“Reserved draw-up %d: n”, i): System.out.println (Arrays.toString(myArray)): } }

    Expert Retort

     

    MySelection.java

    import java.io.File;

    import java.io.FileNotFoundException;

    import java.util.Arrays;

    import java.util.Scanner;

    national class MySegregation {

    national static unfilled ocean(String[] args) throws Exception {

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

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

    int[] myDraw-up = getList(s);

    System.out.printf(“Current draw-up %d.n”, i);

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

    SortArrayUsingSelectionSort(myArray);

    System.out.printf(“Reserved draw-up %d.n”, i);

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

    }

    }

    national static unfilled OrderArrayUsingSelectionSort(int arr[]){

    restraint (int i = 0; i < arr.prolixity – 1; i++)

    {

    int refutation = i;

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

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

    refutation = j;

     

    int smallerNumber = arr[index];

    arr[index] = arr[i];

    arr[i] = smallerNumber;

    }

    }

    national static int[] getList(String finishName) throws FinishNotFoundException {

    Finish finish = strange Finish(fileName);

    Scanner scrutinize = strange Scrutinizener(file);

    int reckon = 0;

    while(scan.hasNextInt()) {

    count++;

    scan.nextInt();

    }

    int[] arr = strange int[count];

    Scanner scrutinize1 = strange Scrutinizener(file);

    reckon = 0;

    while(scan1.hasNextInt()) {

    arr[count] = scrutinize1.nextInt();

    count++;

    }

    return arr;

    }

    }

    Output:

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