Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Java bubble sort Need help! (https://www.askmehelpdesk.com/showthread.php?t=773189)

  • Oct 29, 2013, 11:28 AM
    Mirugan
    Java bubble sort Need help!
    //I need to know what is wrong with this code. It does compile but I don't think it's working properly

    class Bubblesort
    {
    public static void main(String[] args)
    {
    int n[] = {16, 100, 205, 8, 1, 3, 2, 5, 7, 6, 15, 10, 14};
    int l = n.length;
    int I,a,t;
    System.out.print("Given number : ");
    for (i = 0;i < l;i++)
    {
    System.out.print(" " + n[i]);
    }
    System.out.println("\n");
    System.out.print("Accending order number : ");
    for (i=1; I < l; I++)
    {
    for (i=0;i<l-i;i++)
    {
    if (n[i] > n[i+1])
    {
    int temp = n[i];
    n[i] = n[i+1];
    n[i+1] = temp;
    }
    }
    }
    for(i=0;i<l;i++){
    System.out.print(" " + n[i]);
    }
    }
    }
  • Nov 30, 2013, 08:38 AM
    Scleros
    Add some temporary print statements so you can see the value of 'i' for both outer and inner loops as the program runs.

  • All times are GMT -7. The time now is 02:11 AM.