Skip to content

Commit 9ee35e3

Browse files
Create selection_sort.java
Selection Sort using Java as programming Language.
1 parent c3b61c4 commit 9ee35e3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.util.Scanner;
2+
3+
public class SelectionSortExample2
4+
{
5+
public static void main(String args[])
6+
{
7+
int size, i, j, temp;
8+
int arr[] = new int[50];
9+
Scanner scan = new Scanner(System.in);
10+
11+
System.out.print("Enter Array Size : ");
12+
size = scan.nextInt();
13+
14+
System.out.print("Enter Array Elements : ");
15+
for(i=0; i<size; i++)
16+
{
17+
arr[i] = scan.nextInt();
18+
}
19+
20+
System.out.print("Sorting Array using Selection Sort Technique..\n");
21+
for(i=0; i<size; i++)
22+
{
23+
for(j=i+1; j<size; j++)
24+
{
25+
if(arr[i] > arr[j])
26+
{
27+
temp = arr[i];
28+
arr[i] = arr[j];
29+
arr[j] = temp;
30+
}
31+
}
32+
}
33+
34+
System.out.print("Now the Array after Sorting is :\n");
35+
for(i=0; i<size; i++)
36+
{
37+
System.out.print(arr[i]+ " ");
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)