Bubble Sort(Java)
Bubble Sort(Java)
import java.util.Scanner;
arr[i] = in.nextInt(); //Entering the elements into the array in random order
for (int i = 0; i < n - 1; i++) //Loop for tracking the pass number
for (int j = 0; j < n - i - 1; j++) //Loop for tracking rounds in each pass
int t = arr[j];
arr[j] = arr[j+1];
arr[j+1] = t;
}
for (int i = 0; i < n; i++) //Displaying the elements of the arry in Ascending order
System.out.print(arr[i]);
System.out.print(" ");