How to Sort list of Strings in ascending order without using
java api.
Answer / 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 |
State the main difference between c++ and java?
What is a treeset class?
What is anagram in java?
What is string data?
waht happens when a return type ,even void is specified for a constructor?
Can You Have Virtual Functions In Java?
In Java, what’s the purpose of static methods and static variables?
what is purpose of collections.unmodified() method..?
How do you write a conditional statement?
how to handle a singleton service locator. when multiple threads are trying to get the singleton object in same time
Hi friends am new to java. I read jar file means collection of java files. For executing struts application what are the necessary jar files. " struts.jar " file contains what. can u explain
What are the types of collections in java?