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
Why strings in java are called as immutable?
Which command from the jdk compiles a java program?
Explain importance of finally block in java?
Does unicode support all languages?
What is the base class of all classes?
Is java code slower than native code?
What is printwriter in java?
Convert a BST into a DLL and DLL to BST in place.
What interface is extended by awt event listeners?
What is private protected in java?
What is the difference between static (class) method and instance method?
What if I write static public void instead of public static void in java?
Why parameters should be passed by reference?
What is scope of a variable?
How do you make an arraylist empty in java?