Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Explain super keyword in java.

988


When can we say that threads are not lightweight process in java?

1076


What is the difference between overriding and overloading in OOPS.

1072


explain what is transient variable in java?

1059


Why java is made?

917


What are the different types of inheritance in java?

950


What is the flag in java?

990


What methods are used to get and set the text label displayed by a button object?

954


Explain the inheritance?

920


If I don't provide any arguments on the command line, then what will the value stored in the string array passed into the main() method, empty or null?

1199


difference between byte stream class and character stream class?

4483


What is difference between next () and nextline () in java?

937


Can we sort list in java?

936


What are extraneous variables examples?

1010


Will the compiler creates a default constructor if I have a parameterized constructor in the class?

1042