How to Sort Strings which are given in List and display in
ascending order without using java api.
Answer Posted / kumar
public class sorting_strings
{
static void sortString()
{
String a[]={"n","g","a","i","h","v","q"};
for (int i = 0; i < a.length; i++)
{
for (int j = 0; j < a.length; j++) {
int num=a[i].compareTo(a[j]);
//System.out.println("num="+num);
if(num>=0)
{
String temp=a[i];
a[i]=a[j];
a[j]=temp;
}
if(num<0)
{
//String temp=a[i];
a[i]=a[i];
a[j]=a[j];
}
}
}
//display
int x=a.length;
for (int i =(x-1); i>=0 ; i--) {
System.out.print(a[i]+" ");
}
}
public static void main(String[] args) {
sortString();
}
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
How does system arraycopy work in java?
What is a text string?
A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.
Is static variable stored in heap?
What is the difference between static and non-static variables in java programming?
What are the application of stack?
Can we write class inside a class in java?
Why declare Main() method as a static in java ?
What do you mean by stack?
who can i handle multiple client in RMI
Should a main method be compulsorily declared in all java classes?
How do you differentiate abstract class from interface?
What are some examples of variable costs?
List out five keywords related to exception handling ?
What does null mean in java?