-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathselection sort.java
More file actions
46 lines (36 loc) · 805 Bytes
/
selection sort.java
File metadata and controls
46 lines (36 loc) · 805 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
36
37
38
39
40
41
42
43
44
45
46
import java.io.*;
class array
{
public static void main (String args[])throws IOException
{
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader y=new BufferedReader(in);
int i,j,maxpos=0,temp;
int n[] = new int[10];
System.out.println("enter 10 numbers in array");
for(i=0;i<10;i++)
{
n[i]=Integer.parseInt(y.readLine());
}
for(i=0;i<9;i++)
{
maxpos = i;
for(j=i+1;j<10;j++)
{
if(n[j]>n[maxpos])
{
maxpos=j;
}
}
temp=n[i];
n[i]=n[maxpos];
n[maxpos]=temp;
}
System.out.println("content of array after sorting");
System.out.println("n[]");
for(i=0;i<10;i++)
{
System.out.println(n[i]);
}
}
}