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
Do you need to import math in java?
List the different types of classloaders in java.
When can we say that threads are not lightweight process in java?
What is the difference amongst jvm spec, jvm implementation, jvm runtime ?
Explain the advantages of packages in java?
What is difference overloading and overriding?
What is floor in java?
What does business logic mean?
How many bytes is double?
Are floats faster than doubles?
When is the finalize() called?
Is a boolean 1 bit?
Write a program to find maximum and minimum number in array?
What happens if we don’t define serial version uid?
What are peerless components?