# Selection Sort Program in Java

## Selection sort is an in-place comparison sorting algorithm. It has an O(n²) time complexity, which makes it inefficient on large lists, and generally performs worse than the similar insertion sort.

```
import java.util.*;
public class SelectionSort
{
public static void main(String[] args)
{
int ar[] = new int[10];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 10; i++)
{
System.out.print("Enter the number ar[" + i + "]:");
ar[i] = sc.nextInt();
}
System.out.println("The numbers are:");
int n = ar.length;
for (int i = 0; i < n-1; i++)
{
int min = i;
for (int j = i+1; j < n; j++)
{
if (ar[j] < ar[min])
{
min = j;
}
}
int temp = ar[min];
ar[min] = ar[i];
ar[i] = temp;
}
System.out.println("Sorted order:");
for (int i = 0; i < 10; i++)
{
System.out.println(ar[i]);
}
}
}
```

#### Output:

Enter the number ar[0]:12 Enter the number ar[1]:54 Enter the number ar[2]:21 Enter the number ar[3]:36 Enter the number ar[4]:25 Enter the number ar[5]:14 Enter the number ar[6]:47 Enter the number ar[7]:58 Enter the number ar[8]:69 Enter the number ar[9]:85 Sorted order: 12 14 21 25 36 47 54 58 69 85learn java study java

**Recent Posts**

- Capricorn or Kaprekar Number Program in Java October 16, 2021
- LCM and HCF of two numbers Program in C October 6, 2021
- Find day of week from a given date Program in C October 6, 2021
- Difference of two dates in years, months, days Program in C October 6, 2021
- Check whether a date is valid or not Program in C October 6, 2021
- Menu driven Program in C October 6, 2021
- Vowel or consonant Program in C October 6, 2021
- Perform arithmetic calculations on integers Program in C October 6, 2021
- Multiply two positive numbers without using "*" operator October 6, 2021
- Count digits Program in C October 6, 2021
- Product of digits Program in C October 6, 2021
- Print numbers from 1 to 10 using while loop Program in C October 6, 2021
- Find out the grade of a student Program in C October 6, 2021
- Binary Search Program in C October 2, 2021
- Employee Salary Based Program in Java September 10, 2021
- Decimal to Binary Number Program in Java July 3, 2021
- Binary to Decimal Number Program in Java July 3, 2021
- Find biggest number from three given numbers Program in C July 2, 2021
- Find quotient and remainder Program in C July 2, 2021
- Print a message if negative number is entered Program in C July 2, 2021