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
Are variables stored in ram?
Implement two stacks using a single array.
How is Object Oriented Programming different from Procedure Oriented Programming?
What is the use of private static?
Can we write a class without main method in java?
What is nullpointerexception in java?
Why is stringbuffer not immutable?
Tell me about your ability to work under pressure
Can we use both this () and super () in a constructor?
What is the purpose of using javap?
What's the purpose of using break in each case of switch statement?
What is sortedmap interface?
What does exp mean in math?
What’s the difference between constructors and other methods?
What are the states of thread in java?