Blogroll

This blog is created for education about engineering students.All the engineering students are get free downloadable books here. not only books and also different software also available here

3.b. Sorting a list of names



b) Write a Java program for sorting a given list of names in ascending order.
import java.lang.*;
import java.io.*;
class asc
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("enter how many strings");
int n=Integer.parseInt(br.readLine());
String x[]=new String[n];
System.out.print("enter "+n+" strings");
for(int i=0;i
{
x[i]=br.readLine();
}
String s=new String();
for(int i=0;i
{
for(int j=0;j
{
if(x[i].compareTo(x[j])<6)
{
s=x[i];
x[i]=x[j];
x[j]=s;
}
}
}
System.out.print("string in alphebetical order are");
for(int i=0;i
{
System.out.println(x[i]);
}
}
}

No comments:

Post a Comment

Total Pageviews