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


Please Help Members By Posting Answers For Below Questions

Which methods are used during serialization and deserialization process?

552


Explain covariant method overriding in java.

544


When is the garbage collection used in Java?

658


What is boolean example?

529


Can an interface have a class?

567






Write a program to show whether a graph is a tree or not using adjacency matrix.

596


What is sortedmap in java?

553


What is flush () in java?

558


Explain about wait() method?

571


What is the difference between dom and sax parser in java?

533


Can we define package statement after import statement in java?

558


Can a static class implement an interface?

557


Is intellij better than eclipse?

543


What is scanner in java?

543


Explain some best practices you would apply while using collection in java?

569