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 finalize()? Is finalize() similar to a destructor?
What are the types of web technologies?
What is final keyword in java?
According to java operator precedence, which operator is considered to be with highest precedence?
Differentiate between a class and an object.
How does split work in java?
What is command line argument
What do you understand by access specifiers in Java?
Can we assign null to double in java?
How can you set an applet’s height and width as a percentage?
What does main method?
What is mysql driver class name?
What is the method in java?
When is the finalize() called? What is the purpose of finalization?
Can constructor return value?