0

What's wrong with my code?

public class Demo { public final static int MAX = 7; public static intArray = MAX (4, 6, 3, 2, 1, 9, 7); public static void printline(int count) { for(int i = 0; i < count - 1; i++) { System.out.print("="); } System.out.println("="); } public static void display() { System.out.print("["); for(int i = 0; i < MAX; i++) { System.out.print(intArray.get(i) + " "); } System.out.println("]"); } public static void selectionSort() { int indexMin; for(int i = 0; i < MAX - 1; i++) { indexMin = i; for(int j = i + 1; j < MAX; j++) { if(intArray.get(j) < intArray.get(indexMin)) { indexMin = j; } } if(indexMin != i) { System.out.println("Items swapped: [ " + intArray.get(i) + ", " + intArray.get(indexMin) + " ]"); int temp = intArray.get(indexMin); intArray.set(indexMin, intArray.get(i)); intArray.set(i, temp); } System.out.print("Iteration " + (i + 1)); display(); } }

13th Jan 2022, 2:54 AM
Supremo Ace
Supremo Ace - avatar
1 Answer
0
public static void main(String[] args) { System.out.print("Input Array: "); display(); printline(50); selectionSort(); System.out.print("Output Array: "); display(); printline(50); } }
13th Jan 2022, 2:54 AM
Supremo Ace
Supremo Ace - avatar