/* Java program to implement Bubble Sort in Ascending order(Smallest to Largest) */
import java.util.Scanner;
public class Bubble_Sort
public static void main(String args[])
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of elements in the array:");
int n = in.nextInt(); //Represents the number of elements
int arr[] = new int[n]; //Declaring the array
System.out.println("Enter the elements of the array:");
for (int i = 0; i < n; i++)
arr[i] = in.nextInt(); //Entering the elements into the array in random order
//Performing Bubble Sort
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
if (arr[j] > arr[j + 1]) //Swapping of elements
int t = arr[j];
arr[j] = arr[j+1];
arr[j+1] = t;
}
System.out.println("The elements of the Sorted Array are:");
for (int i = 0; i < n; i++) //Displaying the elements of the arry in Ascending order
System.out.print(arr[i]);
System.out.print(" ");