Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Public class ArregloNumeros {

Private static void swap(int[] arr, int i, int j) {


Int temp = arr[i];
Arr[i] = arr[j];
Arr[j] = temp;
}

Public static void sortArray(int[] arr) {


Int n = arr.length;
For (int i = 0; i < n – 1; i++) {
Int maxIndex = i;
For (int j = i + 1; j < n; j++) {
If (arr[j] > arr[maxIndex]) {
maxIndex = j;
}
}
If (maxIndex ¡= i) {
Swap(arr, i, maxIndex);
}
}
}

Public static void main(String[] args) {


Int[] nums = {5, 3, 8, 1, 2, 7, 4, 10, 6, 9};
sortArray(nums);
System.out.println(“Arreglo ordenado de mayor a menor:”);
For (int num : nums) {
System.out.print(num + “ “);
}
}
}

You might also like