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
Which methods are used during serialization and deserialization process?
Explain covariant method overriding in java.
When is the garbage collection used in Java?
What is boolean example?
Can an interface have a class?
Write a program to show whether a graph is a tree or not using adjacency matrix.
What is sortedmap in java?
What is flush () in java?
Explain about wait() method?
What is the difference between dom and sax parser in java?
Can we define package statement after import statement in java?
Can a static class implement an interface?
Is intellij better than eclipse?
What is scanner in java?
Explain some best practices you would apply while using collection in java?