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
Is age discrete or continuous?
Why are there no global variables in java?
How hashmap increases its size in java?
What is meant by attribute?
What are the four corner stones of oop?
What steps are taken when the OS shifts from one-thread execution to another?
What is bifunction in java?
What is the difference between overriding and overloading in OOPS.
Is null in java?
Differentiate between stringbuffer and stringbuilder in java.
What is the purpose of final keyword and when to use it?
What is a vector in java?
What is the difference between java applets and applications?
Which is the class in java?
What is substring in java?