-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSelection.java
More file actions
49 lines (40 loc) · 1.1 KB
/
Copy pathSelection.java
File metadata and controls
49 lines (40 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package Sorting_Algo;
import java.util.Scanner;
public class Selection {
public static void main(String args[]) {
int size, i, j, temp, small, index = 0, count=0;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Array Size : ");
size = scan.nextInt();
int arr[] = new int[size];
System.out.print("Enter Array Elements : ");
for(i=0; i<size; i++)
{
arr[i] = scan.nextInt();
}
for(i=0; i<(size-1); i++) {
small = arr[i];
for(j=(i+1); j<size; j++)
{
if(small>arr[j])
{
small = arr[j];
count++;
index = j;
}
}
if(count!=0)
{
temp = arr[i];
arr[i] = small;
arr[index] = temp;
}
count=0;
}
System.out.print("Now the Array after Sorting is : ");
for(i=0; i<size; i++)
{
System.out.print(arr[i]+ " ");
}
}
}