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 Constructor possible in abstract class in java ?
What access modifiers can be used for variables?
What are the differences between string, stringbuffer and stringbuilder?
How to use Media tracker Class.
Where local and global variables are stored?
What is bifunction in java?
What is jdbc api?
What is bytecode verifier?
How do you reverse sort a list in java?
What is a 16 bit word?
What is comparable and comparator interface? List their differences
What is a parameter example?
Why is it called a string?
Where are local variables stored?
State the difference between creating string as new () and literal.