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


Please Help Members By Posting Answers For Below Questions

What is continuity of a function?

806


What are identifiers in java?

820


What is an enumeration?

805


How can we use primitive data types as objects?

763


Write a java program to count the number of words present in a string?

761


Explain the difference between jvm and jre?

819


What is the base class in java from which all classes are derived?

770


What is set in java?

798


Can a constructor be private and how are this() and super() method used with constructor?

767


Where we write javascript code in html page?

839


How many bits is a 64 bit byte?

787


Why do we need data structure in java?

838


What is meant by main method?

821


How to perform bubble sort in java?

811


Explain the different forms of polymorphism?

792