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

How does callback work in java?

601


Write a program to find maximum and minimum number in array?

546


Can you explain the usages of class.forname()?

600


What is the difference between break and continue statements?

545


Can we have a try block without catch block?

561






What do you mean by buffering?

548


What will be the default values of all the elements of an array defined as an instance variable?

544


What is meant by attribute?

590


What is a newline character in java?

563


Why is string class considered immutable?

593


What is better- service oriented or batch oriented solutions?

1523


What is byte data type?

546


Can we have multiple classes in single file ?

594


can used Protected Class outside Function.?

608


What do you mean by garbage collection used in java?

567