Instructions (Pg. J687) Exercises PE14.2-SortCoins Modify the selection sort algorithm to sort an array of coins by thei
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Instructions (Pg. J687) Exercises PE14.2-SortCoins Modify the selection sort algorithm to sort an array of coins by thei
1 import java.util.Arrays; 123456 PANGANGAN 3 /**PE14.2 6 */ 7 public class CoinSort Demo 8 { 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 This program demonstrates the selection sort algorithm by sorting an array that is filled with random numbers. 34 35 36 37 } 38 } public static void main(String[] args) { Coin[] a = { new Coin (0.05, "nickle"), new Coin (0.05, new Coin (0.10, new Coin (0.01, new Coin (0.25, new Coin (0.01, new Coin (0.44, "Peso"), new Coin (0.10, "Dime") }; "nickle"), "Dime"), "Penny"), "Quarter"), "Penny"), System.out.println("UNSORTED: "); for (int i = 0; i < a.length; i++){ System.out.print(a + " / "); } SelectionSorter.sort(a); System.out.println("SORTED"); for (int i = 0; i < a.length; i++){ System.out.print(a + " / "); }