Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How does system arraycopy work in java?

1058


What is a text string?

1036


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.

959


Is static variable stored in heap?

924


What is the difference between static and non-static variables in java programming?

913


What are the application of stack?

858


Can we write class inside a class in java?

920


Why declare Main() method as a static in java ?

1021


What do you mean by stack?

1090


who can i handle multiple client in RMI

1834


Should a main method be compulsorily declared in all java classes?

996


How do you differentiate abstract class from interface?

913


What are some examples of variable costs?

893


List out five keywords related to exception handling ?

957


What does null mean in java?

1016