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 |
How many characters is 2 bytes?
How will you calculate the depth of a binary tree if the tree contains 15 nodes?
Difference between Preemptive scheduling vs. Time slicing?
Are strings immutable in java?
what is the difference between @include page and @include file
Difference between serialization and deserialization in java?
Can we define package statement after import statement in java?
Where is core java used?
Is there any sort function in java?
What is the basic of java?
Which class is the immediate superclass of the Container class?
What is OOP's Terms with explanation?