Logica ---> Burbuja.
Presentacion ---> Formulario.
Descarga... click acá
Logica --->Burbuja.
- /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Logica;
/*
*
* @author Danimortal
*/
public class Burbuja {
int numeros[];
public void Ordenar()
{
int temp;
for (int i = 1; i < 10; i++) {
for (int k = 10- 1; k >= i; k--) {
if(numeros[k] < numeros[k-1]){
temp = numeros[k];
numeros[k] = numeros[k-1];
numeros[k-1]= temp;
}
}
}
}
public String Imprimir()
{
String orden = "";
for (int j = 0;j<10;j++)
{
orden = orden + String.valueOf(numeros[j]) + "\n";
}
return (orden);
}
public int[] getNumeros() {
return numeros;
}
public void setNumeros(int[] numeros) {
this.numeros = numeros;
}
}
- /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Presentacion;
import Logica.Burbuja;
import java.io.*;
import javax.swing.JOptionPane;
/**
*
* @author Danimortal
*/
public class Formulario {
public static void main(String arg[]) throws IOException
{
int [] vector_local;
vector_local = new int [10];
Burbuja obj1 = new Burbuja();
JOptionPane.showMessageDialog(null,"Digite los 10 numeros enteros...");
for (int i = 0;i < 10 ;i++)
{
vector_local[i] = Integer.parseInt(JOptionPane.showInputDialog("Numero " + (i + 1) + ":"));
}
obj1.setNumeros(vector_local);
obj1.Ordenar();
JOptionPane.showMessageDialog(null,"El numero MAYOR es " + obj1.getNumeros()[9]);
JOptionPane.showMessageDialog(null,"El numero NENOR es " + obj1.getNumeros()[0]);
JOptionPane.showMessageDialog(null,"El vector ordenado es : \n" + obj1.Imprimir());
}
}
No hay comentarios:
Publicar un comentario