Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphoarty/71efa919476c2a26395016d7fea3bc58 to your computer and use it in GitHub Desktop.
Save graphoarty/71efa919476c2a26395016d7fea3bc58 to your computer and use it in GitHub Desktop.
public class bubbleSort {
private static final int max = 10;
public static void main(String[] args){
int[] array = new int[max];
System.out.println("The array to be sorted is");
for(int i = 0; i < max; i++){
array[i] = (int) (Math.random()*100);
System.out.print(" | " + array[i]);
}
System.out.println(" | ");
//The algorithm
for(int i = 0; i < 9; i++){
for(int j = 0; j < 9; j++){
if(array[j] > array[j+1]){
int temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
System.out.println("The sorted array is");
for(int i = 0; i < max; i++){
System.out.print(" | " + array[i]);
}
System.out.println(" | ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment