Explanation
This Java program implements the Bubble Sort algorithm, which is one of the simplest sorting techniques used to arrange elements in a specific order (ascending in this case).
The core logic revolves around comparing adjacent elements in an array. If the element on the left is greater than the element on the right, they are swapped. This process is repeated for every pair of elements. In each complete pass through the array, the largest unsorted element "bubbles up" to its correct position at the end of the array.
The code includes an optimization: a boolean flag called swapped. If the program completes a full pass through the array without making a single swap, it means the array is already sorted, and the program breaks out of the loop early to save processing time.