//public static method for performing a bubble sort on an int array public class eg43_IntBubbleSorter { //only one static method public static void bubbleSort (int[] array) { int maxElement; //marks the last element to compare int index; //index of an element to compare int temp; //used to swap elements //loop maxElement position (-1 for every loop) for (maxElement = array.length-1; maxElement >=0; maxElement--) { //steps through array until maxElement for (index = 0; index <= maxElement-1; index++) { //compare an element with its (+1)neighbor if (array[index] > array[index+1]) { //swap using temp variable temp = array[index]; array[index]=array[index+1]; array[index+1]=temp; } } //output array System.out.println("\nmaxElement = "+maxElement); for (int element : array) System.out.print(element + " "); } } }