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 a boolean output?
How do I type unicode?
Differentiate between the constructors and methods in java?
Objects or references which of them gets garbage collected?
What is the difference between compiler and jvm?
Can abstract class have private constructor?
What is an example of a conditional statement?
What is the default access specifier for variables and methods of a class?
why using interface interface ?
How do I find and replace in word?
What is the difference between post and put?
What are the types of methodology?
How can we avoid including a header more than once?
Can a source file contain more than one class declaration?
Define iterator and methods in iterator?