Write a java program to get a string of words and print the numbers of each word count in descending order

Answer Posted / anjan singh

import java.io.*;

public class Sample {

/**
* @param args
*/


public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
BufferedReader br= new BufferedReader
(new InputStreamReader(System.in));
System.out.println("enter a sentence:");
String str = br.readLine();
str = str.trim();
String[] strArr = str.split(" ");
for(int i=0;i<strArr.length;i++)
for(int
j=i+1;j<strArr.length;j++)
if(strArr[j].length()
> strArr[i].length())
{
String
x=strArr[j];
strArr[j]
=strArr[i];
strArr[i]=x;
}

System.out.println("output:-");
for(int i=0;i<strArr.length;i++)
System.out.println(strArr[i]);
}
catch(Exception e){}
}

}

Is This Answer Correct ?    12 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I write a self declaration?

763


When object is created and destroyed?

834


Explain wait(), notify() and notifyall() methods of object class ?

814


How does hashmap work in java ?

751


Name four container classes.

755


who can i handle multiple client in RMI

1660


Is 0 a real number?

787


How many types of assembly languages are there?

731


What are the restriction imposed on a static method or a static block of code?

816


List some oops concepts in java?

795


What is user defined exception in Java?

840


What is a priority queue java?

728


Explain about assignment statement?

809


When should the method invokelater() be used?

765


What is serial version uid and its importance in java?

820