Skip to content

Commit ee228b0

Browse files
committed
Added Actividad14_Aplicacion - Unit 5
1 parent b3b7b83 commit ee228b0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package unit05.Actividad14_Aplicacion;
2+
3+
/*
4+
Escribe la función void desordenar (int t []), que cambia de forma aleatoria los elementos contenidos en la tabla t.
5+
Si la tabla estuviera ordenada, dejaría de estarlo.
6+
*/
7+
8+
public class Actividad14 {
9+
public static void main(String[] args) {
10+
int[] array = {12,3,4,5,55,6,5,2};
11+
System.out.println("El array es: "+ java.util.Arrays.toString(array));
12+
System.out.println("Desordenamos el array");
13+
desordenar(array);
14+
System.out.println("El nuevo array es: "+ java.util.Arrays.toString(array));
15+
16+
}
17+
18+
private static void desordenar(int[] array) {
19+
for (int i = 0; i < array.length; i++) {
20+
int indiceAleatorio = (int) (Math.random()*array.length);
21+
int aux = array[i];
22+
array[i] = array[indiceAleatorio];
23+
array[indiceAleatorio] = aux;
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)