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
Explain the concept of hashtables?
which class is the wait() method defined in? : Java thread
Which method you will use to create a new file to store some log data. Each time a new log entry is necessary, write string to the file in java ?
What is number data type?
What is split return?
Can an object subclass another object?
Can we have multiple public classes in a java source file?
Is java type safe?
Is it safe to install java on my computer?
Why main function is static?
What is regex java?
what is heap memory?
What is the difference between the direct buffer and non-direct buffer in java?
What is the difference between method overriding and overloading?
Which one will take more memory: an int or integer?