0% found this document useful (0 votes)
4 views1 page

Bubble Sort Java

The document contains a Java program that implements the Bubble Sort algorithm to sort an array of integers. It defines a method 'bubbleSort' that sorts the array in ascending order and a 'main' method that demonstrates the sorting with a sample array. The sorted array is then printed to the console.

Uploaded by

123456bca987
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Bubble Sort Java

The document contains a Java program that implements the Bubble Sort algorithm to sort an array of integers. It defines a method 'bubbleSort' that sorts the array in ascending order and a 'main' method that demonstrates the sorting with a sample array. The sorted array is then printed to the console.

Uploaded by

123456bca987
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Sorting Program

public class BubbleSort {


public static void bubbleSort(int[] arr) {
int n = [Link];
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}

public static void main(String[] args) {


int[] arr = {5, 1, 4, 2, 8};
bubbleSort(arr);
for (int num : arr) {
[Link](num + " ");
}
}
}

You might also like