Write a java program to get a string of words and print the numbers of each word count in descending order

Answer Posted / gdk

public static void main(String[] args) {
String word = "get the count and arrange in descending order";
String[] temp = word.split(" ");
for (int index = 0; index < temp.length; index++) {
for (int i = index+1; i < temp.length; i++) {
if (temp[i].length() > temp[index].length()) {
String word2 = temp[i];
temp[i] = temp[index];
temp[index] = word2;
}
}
System.out.println(temp[index] +" " +temp[index].length());
}
}

Is This Answer Correct ?    28 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which class is used by server applications to obtain a port and listen for client requests?

734


Why synchronization is important in java?

811


Explain when classnotfoundexception will be raised ?

819


How do you empty a list in java?

779


What is the unit of plancks constant?

814


Highest level event class of the event-delegation model?

3738


Can we clone singleton object in java?

809


who can i handle multiple client in RMI

1686


Does java support Operator Overloading?

841


What is your platform’s default character encoding?

809


What java is used for?

857


What does string intern() method do?

857


What is port number in java?

825


Why do we need singleton class?

763


What is argument in java?

795