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 are the different types of methodologies?
Can you override private or static method in java?
what is predefined function in java?
Why are arrays useful in java?
How can you say java is object oriented?
Does isempty check for null?
how to split string in java?
What is string :: npos?
How do you implement tree mirroring in java?
Which class is used by server applications to obtain a port and listen for client requests?
What is a super method?
What is the functionability stubs and skeletons?
What's the purpose of static methods and static variables?
What is volatile data type?
What is the difference between stringbuffer and stringbuilder class?