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
Which method cannot be overridden in java?
What is a condition in java?
What is a parameter example?
Why do we use regex?
What is the final blank variable?
What is bool mean?
What is a parameter in java?
What happens if a constructor is declared private?
What access modifiers can be used for class ?
Is string thread safe in java?
What does i ++ mean in Java?
Can we have two main methods in a java class?
What is variable and constant explain with example?
What is thread safe java?
Name the components that are termed to be Heavy-weight component but available in Light-weight components?