Package Mytest;import Java.util.scanner;public class Bubblesort {public void Init (int array[]) {Scanner num = new Scanner (S ystem.in); System.out.println ("Please enter 10 numbers:"); for (int i = 0;i<10;i++) {Array[i] = Num.nextint ();}} Print public void myprint (int array[]) {System.out.println ("The result after sorting is:"); for (int i = 0;i<10;i++) {System.out.print ( array[i]+ "");} System.out.println ();} Bubble sort public void Mybubblesort (Int. array[]) {int temp;for (int i = 0;i<10;i++) {for (int j = 0;j<10-i-1;j++) {if (array[ J]>array[j+1]) {temp = Array[j];array[j] = array[j+1];array[j+1] = temp;}}} SYSTEM.OUT.PRINTLN ("Sorted result is:"); for (int i = 0;i<10;i++) {System.out.print (array[i]+ "");} System.out.println ();} Select sort public void Mychoicesort (Int. array[]) {int temp;for (int i = 0;i<10;i++) {for (int j = i+1;j<10;j++) {if (Array[i] >ARRAY[J]) {temp = Array[j];array[j] = array[j+1];array[j+1] = temp;}}}} Program entry public static void main (string[] args) {bubblesort hehe = new Bubblesort (); int[] array = new Int[10];hehe. Init (array); hehe. MYbubblesort (array); System.out.print ("After bubble sort"); hehe. Myprint (array); hehe. Mychoicesort (array); System.out.print ("After select Sort"); hehe. Myprint (array);}}
Java Sort small algorithm (bubbling and selection)