lunes, 9 de marzo de 2009

Laboratorio3 ejemplo2

  • Necesitamos un programa que ordene 3 números de mayor a menor.



  • //Declaramos las variables
    String Txt1 = "", Txt2 = "", Txt3 = "";
    intnum1 = 0, num2 = 0, num3 = 0;
    int a = 0, b = 0, c = 0;

    //Capturamos los datos desde teclado
    Txt1 = JOptionPane.showInputDialog(null, "Ingrese el primer valor",
    "Ordenar Valores", JOptionPane.INFORMATION_MESSAGE);


    Txt2 = JOptionPane.showInputDialog(null, "Ingrese el segundo valor",
    "Ordenar Valores", JOptionPane.INFORMATION_MESSAGE);


    Txt3 = JOptionPane.showInputDialog(null, "Ingrese el tercer valor",
    "Ordenar Valores", JOptionPane.INFORMATION_MESSAGE);


    //Convertimos los datos en Integer(Enteros)
    num1 = Integer.parseInt(Txt1);
    num2 = Integer.parseInt(Txt2);
    num3 = Integer.parseInt(Txt3);


    //Realizamos la comparacion de datos
    if (num1 >= num2 && num1 >= num3){
    a = num1;
    if (num2 >= num3){
    b = num2;
    c = num3;
    }else{
    c = num3;
    c = num2;
    }
    }
    if (num2 >= num1 && num2 >= num3){
    a = num2;
    if (num1 >= num3){
    b = num1;
    c = num3;
    }else{
    b = num3;
    c = num1;
    }
    }
    if (num3 >= num1 && num3 >= num2){
    a = num3;
    if (num1 >= num2){
    b = num1;
    c = num2;
    }else{
    b = num2;
    c = num1;
    }
    }


    //Imprimos el resultado
    JOptionPane.showMessageDialog(null, a + " " + b + " " + c,
    "Ordenar Valores", JOptionPane.INFORMATION_MESSAGE);

    No hay comentarios:

    Publicar un comentario