Created
March 3, 2019 03:24
-
-
Save graphoarty/71efa919476c2a26395016d7fea3bc58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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