import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int arr[] = new int[n]; for (int i = 0 ; i < n ;i++ ) { arr[i] = sc.nextInt(); } //Selection sort for(int i = 0; i < n-1 ; i++) { int minidx = i; for(int j = i+1 ; j < n ; j++) { if (arr[j] < arr[minidx]) { minidx = j; } // swap int temp = arr[minidx]; arr[minidx] = arr[i]; arr[i] = temp; } } System.out.print(Arrays.toString(arr)); } } 2 type import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt(); int arr [] = new int [n]; for (int i = 0;i < n ;i++ ) { arr[i] = sc.nextInt(); } System.out.println(selectionSort(arr,n)); } public static String selectionSort(int arr [],int n) { for(int i = 0; i < n-1; i++) { int minNum = minInArr(arr,i); //swap int temp = arr[minNum]; arr[minNum] = arr[i]; arr[i] = temp; } return(Arrays.toString(arr)); } public static int minInArr(int arr[],int i) { int minidx = i; for(int j = i+1 ; j < arr.length ; j++) { if (arr[j] < arr[minidx]) { minidx = j; } } return minidx; } }