Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package arreglo;
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- public class arreglo {
- public static void main(String[] args) {
- //Entrada de datos
- Scanner entrada = new Scanner (System.in);
- //Definicion de variables
- int arreglo[], nElementos, auxiliar;
- //Usuario ingresa datos
- nElementos = Integer.parseInt(JOptionPane.showInputDialog("Por favor digite la cantidad de elementos"));
- arreglo = new int [nElementos];
- for(int i=0; i < nElementos; i++ ){
- System.out.println((i+1)+". Ingrese el elemento:");
- arreglo[i] = entrada.nextInt();
- }
- //Muestra del arreglo
- for (int i=0; i < nElementos; i++){
- System.out.print(arreglo[i]+" - ");
- }
- //Método Burbuja
- for(int i = 0; i < nElementos; i++){
- for(int j = 0; j < nElementos; j++){
- if (arreglo[j] > arreglo[j+1]){
- auxiliar = arreglo[j];
- arreglo[j] = arreglo[j+1];
- arreglo[j+1] = auxiliar;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement