Write a java program to get a string of words and print the numbers of each word count in descending order
Answer Posted / shubhasish
public class WordCount {
private String word;
private Long wordCount;
public WordCount(String word) {
this.word = word;
}
public void displayWordCount() {
String[] temp = word.split(" ");
for (int index = temp.length - 1; index >= 0; index--) {
System.out.println(temp[index] + "-->" +
temp[index].length());
}
}
public static void main(String args[]) {
WordCount wordCount = new WordCount("I Will Crack
This");
wordCount.displayWordCount();
}
}
Is This Answer Correct ? | 12 Yes | 8 No |
Post New Answer View All Answers
What is continuity of a function?
What are identifiers in java?
What is an enumeration?
How can we use primitive data types as objects?
Write a java program to count the number of words present in a string?
Explain the difference between jvm and jre?
What is the base class in java from which all classes are derived?
What is set in java?
Can a constructor be private and how are this() and super() method used with constructor?
Where we write javascript code in html page?
How many bits is a 64 bit byte?
Why do we need data structure in java?
What is meant by main method?
How to perform bubble sort in java?
Explain the different forms of polymorphism?