
Ordenamiento de Array en Java
Java
Publicado el 3 de Enero del 2022 por Alexander (15 códigos)
756 visualizaciones desde el 3 de Enero del 2022
Ordenamiento de arrays con Java
package hoja1;
/**
*
* @author alexandersanchez
*/
public class Ejercicio7 {
public static void main(String[] args) {
int[] numRandom = new int[10];
int aux = numRandom[0];
for (int i = 0; i < numRandom.length; i++) {
numRandom[i] = (int) (Math.floor(Math.random() * 10) + 1);
}
for (int x = 0; x < numRandom.length; x++) {
System.out.println("resultados indice " + x + " = " + numRandom[x]);
}
System.out.println("******************************");
for (int k = 0; k < numRandom.length; k++) {
for (int y = 0; y < numRandom.length; y++) {
if (y < numRandom.length - 1) {
if (numRandom[y] < numRandom[y + 1]) {
aux = numRandom[y];
numRandom[y] = numRandom[y + 1];
numRandom[y + 1] = aux;
}
}
}
}
for (int x = 0; x < numRandom.length; x++) {
System.out.println("resultados indice " + x + " = " + numRandom[x]);
}
}
}
Comentarios sobre la versión: 1 (0)
No hay comentarios