Please help!!!!!!!!!11

Discussion in 'Software' started by kenny770, Feb 14, 2005.

  1. kenny770

    kenny770 Private E-2

    Hi guys im new to programming but im gettin there anyways i have this sorting program thats puts integers num1, num2, and num3 in order from least to greatest. I got the first to conditons where (num1>=num2) and (num2>=num3) but i cant get it right for (num1>=num3). i want it to say 1,2,3 but when i test it with 3,2,1 i get 2,3,1. any help or suggestions you guys can give would be real coo here is the code:


    import javax.swing.JOptionPane;

    public class Sort{
    public static void main(String []args){

    String nu1, nu2, nu3;
    int num1, num2, num3;
    int temp;

    String nu1String = JOptionPane.showInputDialog(null, "Enter the first number:", "First Number", JOptionPane.QUESTION_MESSAGE);

    num1 = Integer.parseInt(nu1String);

    String nu2String = JOptionPane.showInputDialog(null, "Enter the second number:", "Second Number", JOptionPane.QUESTION_MESSAGE);

    num2 = Integer.parseInt(nu2String);

    String nu3String = JOptionPane.showInputDialog(null, "Enter the third number:", "Third Number", JOptionPane.QUESTION_MESSAGE);

    num3 = Integer.parseInt(nu3String);

    if((num1<=num2) && (num2<=num3)){
    JOptionPane.showMessageDialog(null, num1+ " and "+num2 +" and "+num3 +" are in order", "Sorting", JOptionPane.INFORMATION_MESSAGE);
    }
    else if(num1>=num2){
    temp = num2;
    num2 = num1;


    JOptionPane.showMessageDialog(null, temp+ " and " +num2 +" and" +num3 + " are now in order", "Sorting", JOptionPane.INFORMATION_MESSAGE);
    }

    else if(num2>=num3){
    temp = num3;
    num3 = num2;

    JOptionPane.showMessageDialog(null, num1+ " and " +temp +" and" +num3 + " are now in order", "Sorting", JOptionPane.INFORMATION_MESSAGE);
    }

    else if(num1>=num3){
    temp = num3;
    num2 = num2;
    num1 = num1;

    JOptionPane.showMessageDialog(null, temp+ " and " +num2 +" and" +num1 + " are now in order", "Sorting", JOptionPane.INFORMATION_MESSAGE);
    }

    System.exit(0);


    }
    }
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds