Write a java program to get a string of words and print the numbers of each word count in descending order
Answer Posted / pradeepta kumar mishra
package interview;
import java.util.*;
import java.io.*;
class WordCount{
public static void main(String[] args) {
int count =0;
try{
BufferedReader br= new BufferedReader(new
InputStreamReader(System.in));
System.out.println("enter a sentence:");
String str = br.readLine();
List<Integer> l = new ArrayList<Integer>();
for(int k=str.length();k>=1;k--)
{
if(str.charAt(k-1)==' ')
{
l.add(count);
count=-1;
}
count++;
}
l.add(count);
Comparator<Integer> comparator =
Collections.reverseOrder();
Collections.sort(l,comparator);
System.out.println("Number of each word in
desc order --"+l);
}
catch(Exception e){
}
}
}
Is This Answer Correct ? | 2 Yes | 3 No |
Post New Answer View All Answers
Why Java is not pure Object Oriented language?
What are the 6 mandatory procedures for iso 9001?
How many decimal digits is 64 bit?
Explain enumeration in java?
What is navigable map in java?
What are voids?
When should you make a function static?
What does ide stand for?
What do you mean by platform independence of Java?
What is keyword auto for?
Can we modify the throws clause of the superclass method while overriding it in the subclass?
How do you reverse sort a list in java?
What does a boolean method return?
What is a condition in java?
How is tree Mirroring implemented?