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
What’s the difference between callable and runnable?
What does serializing data mean?
What is finally block?
Can we create object of inner class in java?
Where are local variables stored?
What is the use of java?
What is size of int in java?
what is object slice?
Tell some latest versions in JAVA related areas?
How to change the priority of thread or how to set the priority of thread?
What does flagged out mean?
public class Test { public static void main(String[] args) { int countA = 0; int countB = 0; int countC = 0; int countD = 0; int countE = 0; int countF = 0; int countG = 0; int countH = 0; int countI = 0; int countJ = 0; int countK = 0; int countL = 0; int countM = 0; int countN = 0; int countO = 0; int countP = 0; int countQ = 0; int countR = 0; int countS = 0; int countT = 0; int countU = 0; int countV = 0; int countW = 0; int countX = 0; int countY = 0; int countZ = 0; } } Can anybody tell me any alternate solution(like loop or something) to automate this initialization process. Ex:- for(char chr='A';chr<='Z'; chr++) { (int) String "count"+chr = 0; }
What means public static?
What do you understand by java?
Can we overload run() method in java?