-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelection_sort.java
More file actions
31 lines (31 loc) · 956 Bytes
/
Selection_sort.java
File metadata and controls
31 lines (31 loc) · 956 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
import java.io.*;
public class Selection_sort
{
public static void main(String[] args)throws IOException
{
int i,j,m;
String t="";
System.out.println("\t Selection Sort for String\n");
BufferedReader as=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the Number of Array Elements you wanna ENTER:");
int n=Integer.valueOf(as.readLine());
String a[]=new String[n];
System.out.println("Enter the Strings Consecutively:");
for(i=0;i<n;i++)
a[i]=as.readLine();
for(i=0;i<(n-1);i++)
{
m=i;
for(j=i+1;j<n;j++)
if(a[m].compareTo(a[j])>0)
m=j;
t=a[m];
a[m]=a[i];
a[i]=t;
}
System.out.println("\nThe Newly Arranged array:");
for(i=0;i<n;i++)
System.out.println(a[i]);
System.out.println("\n------------------------------------------");
}
}