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 namespace in java?

769


What is the use of predicate in java 8?

706


What is prefix of a string?

808


How does hashmap work in java ?

754


Give us a program to check for parenthesis matching using stack.

762


Why can't we make a class private in java?

785


What is == mean?

758


What is a singleton puppy?

745


How do I know if java is installed?

784


Can we access the non-final local variable, inside the local inner class?

780


What are the advantages of inner classes?

750


What does g mean in regex?

754


What is field name?

779


How do you ensure that n threads can access n resources without deadlock?

1087


Is java free for businesses?

816