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
What Is Composition?
What is the this keyword?
What language is pass by reference?
How do you do math powers in java?
What are the basic control structures?
What are annotations in java?
What will happen if static modifier is removed from the signature of the main method?
What is a class variable?
What is == in java?
Explain about the dynamic behavior of core java?
Why is string buffer better than string ?
how to deploy apache tomcat server to weblogic server in java
Is a case study a method or methodology?
What is thread count in java?
Differentiate between a class and an object.