Java Programming

Bubble Sort

Java programming example for sorting using bubble sort algorithm

9/29/2021
0 views
bubble-sort.javaJava
import java.io.*;

class sort {

	/* Constructor of the class */
	sort(int ... array) {
		for(int i = 0; i < array.length; i++) {
			for(int j = i + 1; j < array.length; j++) {
				if(array[j] < array[i]) {
					int temp = array[i];
					array[i] = array[j];
					array[j] = temp;
				}
			}
		}
		System.out.println("Sorted array:");
		for(int k:array)
			System.out.println(k);
	}
}
										
class bubblesort {
	public static void main(String args[ ]) {
		new sort(6,2,4,1,3,0,5,8,7,9);
	}
}



/* Output */
Sorted array:
0
1
2
3
4
5
6
7
8
9
Java TutorialBubble Sort

Related Examples