//Sorting demo import javax.swing.JOptionPane; public class SortThem { public static void main ( String args[] ) { int c[] = { 3, 6, 1, 9, 2, 8 }; //the array int temp; //just to hold a value //show the array values in order. for ( int j = 0 ; j < c.length ; j++ ) System.out.print ( c [ j ] + " " ); System.out.println(); //create a pause before sorting begins. JOptionPane.showMessageDialog ( null , "Start sorting " ); for ( int pass = 1 ; pass < c.length ; pass++ ) { //use c.length - 1 to keep array index in bounds for ( int i = 0 ; i < c.length - 1 ; i++ ) { //note: "greater than" used to compare two elements if ( c [ i ] > c [ i + 1 ] ) { temp = c [ i ]; //hold c[i] temporarily c [ i ] = c [ i + 1 ]; //assign c[i+1] to c[i] position c [ i + 1 ] = temp; //put temp value in c[i+1] } //show the array values in order after one sort. for ( int j = 0 ; j < c.length ; j++ ) System.out.print ( c [ j ] + " " ); System.out.println(); //create a pause before sorting continues. JOptionPane.showMessageDialog ( null , "Keep sorting " ); } //create a pause before the next round of sorting starts. JOptionPane.showMessageDialog ( null , "Next pass through: " ); } System.exit ( 0 ); } }