Ask Experts Questions for FREE Help !
Ask
    Mirugan's Avatar
    Mirugan Posts: 1, Reputation: 1
    New Member
     
    #1

    Oct 29, 2013, 11:28 AM
    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]);
    }
    }
    }
    Scleros's Avatar
    Scleros Posts: 2,165, Reputation: 262
    Hardware Expert
     
    #2

    Nov 30, 2013, 08:38 AM
    Add some temporary print statements so you can see the value of 'i' for both outer and inner loops as the program runs.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Java netbeans program- Connection between java and mysql,How to conn [ 0 Answers ]

which I wrote from a book but when I run it, it shows exception please give me the code to connect jlistbox to database when I click on btn1. btn coding should search "name" in database and shows all the names in listbox my coding: here-- r1,r2,r3 are radio btns and l1,l2,l3 are labels,...

Full program for the bubble sort algorithm [ 1 Answers ]

Full program for the bubble sort algorithm

Sort a Column & sum the range with same value during the sort [ 2 Answers ]

Hi, I'm trying to sort a data table by Grades & then sum the totals of the cell with same Grade. The table consists of this headers: Date, DD#, Grade, Bags so what I'm trying to do is to come up with a formula that can sort by Grade & then add the total Bags against that particular Grade and...

Bubble, bubble, toilet trouble! [ 1 Answers ]

We live in a 2 bath home, ranch style. The toilet and shower in the master are fine, as is the kitchen sink and the laundry room. In the main bath, my toilet won't drain, when plunged out it backs into the tub drain. Also, when I run the water in the tub, it makes the toilet bubble. Same thing...


View more questions Search