-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselsort.java
More file actions
35 lines (33 loc) · 992 Bytes
/
Copy pathselsort.java
File metadata and controls
35 lines (33 loc) · 992 Bytes
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
import java.util.Scanner;
public class selsort {
public static void main(String[] args) {
try (Scanner ab = new Scanner(System.in)) {
int[] arr;
System.out.println("limit");
int n = ab.nextInt();
arr = new int[n];
for (int i = 0; i < arr.length; i++) {
System.out.println("element number" + (i + 1) + " : ");
arr[i] = ab.nextInt();
}
selsort ob = new selsort();
ob.ssort(arr);
}
}
void ssort(int ar[]) {
for (int i = 0; i < ar.length; i++) {
int min = i;
for (int j = i + 1; j < ar.length; j++) {
if (ar[j] < ar[min]) {
min = j;
}
}
int temp = ar[i];
ar[i] = ar[min];
ar[min] = temp;
}
for (int i = 0; i < ar.length; i++) {
System.out.println(ar[i] + " ");
}
}
}