Write a java program to get a string of words and print the numbers of each word count in descending order
Answer Posted / megha shetty
public class Inc {
public static void main(String[] args) {
// TODO Auto-generated method stub
String temp;
String s="this is my way of doing it";
String s1[]=s.split(" ");
for(int j=1;j<=s1.length-1;j++)
for(int i=0;i<s1.length-j;i++)
{
if(s1[i].length()<s1[i+1].length())
{ temp=s1[i];
s1[i]=s1[i+1];
s1[i+1]=temp;
}
}
System.out.println("
new sorted array:
");
for(String i:s1)
System.out.println(i+" the length is "+i.length());
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?
How do listeners work?
What are the restrictions imposed by a Security Manager on Applets?.
What is use of static in java?
Enlist diffrent types of inheritance supported by java?
What is %02d?
Difference between Linked list and Queue?
How to declare an arraylist in java?
What is meant by nested loop?
Can I learn java in 3 months?
What is difference between Heap and Stack Memory?
What are extraneous variables examples?
When the constructor of a class is invoked?
What is difference between null and void?
What are generic methods?