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

What is anagram word?

523


Give any two differences between C++ and java.

560


What is polymorphism and what are the types of it?

508


What is purpose of keyword void?

567


What is array class in java?

596






Why multiple inheritance is not supported by java?

514


How to make object serializable in java?

553


What is use of static method?

536


Is java type safe?

513


What are data types in programming?

553


Print Vertical traversal of a Binary Tree.

611


What is abstract class? Explain

597


Is the empty set a singleton?

543


What is the function of log?

546


What is use of valueof () in java?

564