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 tree set and its features?
What is the main difference between java platform and other platforms?
If a variable is declared as private, where may the variable be accessed?
What are basic keywords?
what is object-oriented programming in java?
Outline the major features of java.
Define inheritance?
What is difference between java and java ee?
What are the two basic ways in which classes that can be run as threads may be defined?
Is 0 an irrational number?
What class allows you to read objects directly from a stream?
State two differences between C and Java.
What is the difference between static and non-static variables in java programming?
What is a file pointer?
Can a method be static?