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 |
There can be a abstract class without abstract methods, but what is the need to declare a class abstract if it doesn't contain abstract methods?
Is char a method in java?
Is java free for businesses?
What is jit compiler ?
What is runtime polymorphism or dynamic method dispatch?
Are there structures in java?
A class can be a subclass of itself?
What is a protected class in java?
Explain the usage of this with constructors?
What happens if we don’t define serial version uid?
Can we convert integer to string in java?
What are the restrictions imposed on method overriding?