So i found a code thats the Java equivalent of the bubble sort algorithm, i understand parts of it, but the thing is i dont get how it works, specifically the loops which i assume do much of the work, can somebody please explain to me, i swear if i had 1 thousand dollars i would give to you if you explained well, but all i got is points to give... sooo pleaase i know its tedious but again pleease:

public class Bubble {

public static void main (String args[]){
System.out.println("Bubble sort algorithm:");
int name [] = {7,3,4,20,6};

for(int x = 0; x<name.length;x++){
System.out.print(name[x] + " ");}

for (int x = name.length-1; x > 0; x-- ){
for(int y = 0; y < name.length-1; y++){
int temp = name[y];
int tempo = name[y+1];
if(name[y]>name[y+1]){
name[y]=tempo;
name[y+1]=temp;

}	
}}

System.out.println();
for(int x=0; x<name.length;x++){
System.out.print(name[x]+ " ");

}


}

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.