How to Sort Strings which are given in List and display in
ascending order without using java api.
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 |
How do you implement polymorphism in our day to day life?
How do I type unicode?
What causes memory leak in java?
What is the difference between final, finally and finalize() in java?
as we know a static method could access static data and static method only. then how could main method call the object of aclass which is not static and other non static data
What is the default size of load factor in hashing based collection?
What are the different types of data structures in java?
steps to connect with Oracle Databse using TYPE-2 Jdbc driver.
Is a char always 1 byte?
What is update method called?
What is inheritance?
5 Answers Accenture, Hexaware, Syntel,
What is the difference between post and put?