Example: Java Program to Implement Bubble Sort Algorithm
Output 1
Choose Sorting Order: 1 for Ascending 2 for Descending 1 Sorted Array: [-9, -2, 0, 11, 45]
In this case, we have entered 1 as input. Hence, the program sort the array in ascending order.
Output 2
Choose Sorting Order: 1 for Ascending 2 for Descending 2 Sorted Array: [45, 11, 0, -2, -9]
In this case, we have entered 2 as input. Hence, the program sort the array in descending order.
If you want to learn more about the bubble sort algorithm, visit Bubble Sort Algorithm.
Note: We have used the Java Scanner Class to take input from the user.