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 |
What is double in java?
Can one thread block the other thread?
What is the exact difference in between Unicast and Multicast object ?
What is a Presistent Object?
0 Answers InfoAxon Technologies,
Difference between String and String Buffer?
What is the benefit of lambda expressions?
What is the use of static import ?
What is encapsulation? Elaborate with example?
What is a loop java?
What is difference between path and classpath variables?
Write a method to check if input string is palindrome?
Create a form of user Login in JSP, that accepts the user name and password from user and authenticate it with user names and passwords stored in database. (Plz provide me answer immediately)