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
Difference between serialization and deserialization in java?
What are the classes of java?
Why do I need to declare the type of a variable in java?
Can we have try block without catch block?
What is the difference between serializable and externalizable interfaces?
Can a source file contain more than one class declaration?
Can you explain the usages of class.forname()?
What is the abstract class?
What do you understand by soft reference?
What is a Presistent Object?
Can I learn java without any programming experience?
Why are functions called methods in java?
Which method must be implemented by all threads?
What is the purpose of the System class?
What is a boolean in java?