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

what is difference between equals and ==?

1119


Can a class be defined inside an interface?

1076


Variables used in a switch statement can be used with which datatypes?

1037


Can we have a try block without catch block?

1051


How are the elements of a gridbaglayout organized in java programming?

1025


What is a lambda expression ? What's its use ?

1155


What is volatile data type?

1067


How big is a 64 bit float?

1070


How many arguments can a method have java?

1067


What is the difference between length and length() method in java?

1171


What does snprintf return?

1055


Why to use nested classes in java? (Or) what is the purpose of nested class in java?

1121


how many types of Inheritance?

1213


Which sorting algorithm is best in java?

1023


Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?

1285