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 return keyword in java?
Explain yield() method in thread class ?
diffrence b\w println() and printf()
Is it possible to specify multiple jndi names when deploying an ejb?
What is not object oriented programming?
what do you mean by classloader in java?
My application URL : http://localhost:8080/Application/Login.jsp. When a user enter this url in IE then, how it get Login.JSP Page exactly? what are the processes will happen from when we submit the URL to get Login.jsp?
What is basic concept of static in java ?
How many JVMs can run on a single machine and what is the Just-In-Time(JIT) compiler?
Explain restrictions on using enum?
What are data structures in java?
if a java file without any source code is valid java file?