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
Why generics are used in java?
Is java 11 paid version?
What is the base class of all exception classes in java?
how do I create a runnable with inheritance? : Java thread
What happens if we override only equals?
What is identifier give example?
What does three dots mean in java?
Explain about oops concepts.
What is the byte order of byte buffer?
Explain about the performance aspects of core java?
What are data types in programming?
Which class contains a method: cloneable or object?
Which is the class in java?
How do you implement tree mirroring in java?
What is the function of static in java?