How to Sort list of Strings in ascending order without using
java api.

Answer Posted / megha

package practise;

import java.util.Scanner;

class Sorting {
public static void main(String[] input)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the count :\t ");
int k=sc.nextInt();
String temp=new String();
String names[]=new String[k];
System.out.println("enter the names");
for(int i=0;i<k;i++)
{
names[i] = sc.next();
}
for( int i=0;i<k;i++)
{
for(int j =i+1;j<k;j++)
{
if(names[i].compareTo(names[j])>0)
{
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
for(String name:names)
{
System.out.println(name);
}
}
}

Is This Answer Correct ?    25 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which method cannot be overridden in java?

590


What is a condition in java?

533


What is a parameter example?

520


Why do we use regex?

553


What is the final blank variable?

584






What is bool mean?

562


What is a parameter in java?

542


What happens if a constructor is declared private?

525


What access modifiers can be used for class ?

534


Is string thread safe in java?

576


What does i ++ mean in Java?

496


Can we have two main methods in a java class?

534


What is variable and constant explain with example?

525


What is thread safe java?

489


Name the components that are termed to be Heavy-weight component but available in Light-weight components?

1980