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
What is the use of volatile in java?
What is the this keyword?
What’s the difference between constructors and other methods?
Why there is no call by reference in java?
Can we force the garbage collection to run?
Why do we need singleton class?
Does java arraylist maintain insertion order?
Explain about abstract classes in java?
Can you override static methods?
What are java methods?
How do you replace all in word?
What are the types of literals?
Can we use string in switch case in java?
What does indexof mean?
Is null a string or object in java?