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
Which class is used by server applications to obtain a port and listen for client requests?
Why synchronization is important in java?
Explain when classnotfoundexception will be raised ?
How do you empty a list in java?
What is the unit of plancks constant?
Highest level event class of the event-delegation model?
Can we clone singleton object in java?
who can i handle multiple client in RMI
Does java support Operator Overloading?
What is your platform’s default character encoding?
What java is used for?
What does string intern() method do?
What is port number in java?
Why do we need singleton class?
What is argument in java?