-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray.java
63 lines (51 loc) · 1.83 KB
/
Array.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package co.edu.uniquindio.poo;
import java.util.Arrays;
import java.util.Scanner;
public class Array {
private int[] arreglo;
public Array(int[] arreglo){
this.arreglo = arreglo;
}
public Array(){
}
public int asignarTamanioArray(){
// Solicita al usuario que ingrese el tamaño del array.
Scanner sc = new Scanner(System.in);
System.out.println("ingrese el tamaño del array: ");
int tamanio = sc.nextInt();
return tamanio;
}
public void crearArray(int tamanio){
// Solicita al usuario que ingrese los elementos del array.
arreglo = new int[tamanio];
Scanner sc = new Scanner(System.in);
for(int i=0; i<arreglo.length;i++){
System.out.println("Ingrese el elemento " + i + " de la lista que tiene un tamaño de " + tamanio);
int numero = sc.nextInt();
arreglo[i] = numero;
}
sc.close();
}
public void ordenarArrayMetodoBurbuja(){
// Ordena el array utilizando el algoritmo de ordenamiento de burbuja.
for(int i=0;i<arreglo.length;i++){
for(int j=0;j<arreglo.length-1;j++){
int elementoActual = arreglo[j];
int elementoSiguiente = arreglo[j+1];
if(elementoActual>elementoSiguiente){
arreglo[j]= elementoSiguiente;
arreglo[j+1]= elementoActual;
}
}
}
}
public String generarMensaje(){
// Genera un mensaje que indica que el array se ha ordenado.
String mensaje ="La arreglo organizado numéricamente por el método " + Arrays.toString(arreglo);
return mensaje;
}
public void mostrarMensaje(String mensaje){
// Muestra el mensaje al usuario.
System.out.println(mensaje);
}
}