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
Can list have duplicates in java?
what is collatration?
When is update method called?
Explain access specifiers?
Why synchronization is important in java?
Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.
Make a data structure and implement an algorithm to print all the files in a directory. (The root directory can have sub-directories too.)
what is meant wrapper classes?
How to display names of all components in a Container?
Difference between concurrent hashmap and hashtable and collections
What is meant by distributed application? Why are we using that in our application?
What do you understand by an io stream?
How do you replace a string in java?
What is string pool?
Is there any difference between nested classes and inner classes?