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

Selection Sort Java

The document contains a Java program that implements the Selection Sort algorithm to sort an array of integers. It defines a method 'selectionSort' that rearranges the elements in ascending order and a 'main' method to demonstrate its functionality 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)
5 views1 page

Selection Sort Java

The document contains a Java program that implements the Selection Sort algorithm to sort an array of integers. It defines a method 'selectionSort' that rearranges the elements in ascending order and a 'main' method to demonstrate its functionality 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 SelectionSort {


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

public static void main(String[] args) {


int[] arr = {64, 25, 12, 22, 11};
selectionSort(arr);
for (int num : arr) {
[Link](num + " ");
}
}
}

You might also like