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 default switch case? Give example.

800


Which is illegal identifier in java?

806


What is difference between == equals () and compareto () method?

761


Is singleton thread safe in java?

762


What is externalizable?

849


What is a static method in java?

787


Can abstract class have private constructor?

732


What's the purpose of using break in each case of switch statement?

783


What does java edition mean?

786


Can you make a constructor final?

802


Can constructor return value?

760


How is treeset implemented in java?

759


What are the important features of Java 9 release?

771


What do you know about the garbage collector in java?

836


What is a stack class in java ?

875