Write a java program to get a string of words and print the numbers of each word count in descending order

Answer Posted / gdk

public static void main(String[] args) {
String word = "get the count and arrange in descending order";
String[] temp = word.split(" ");
for (int index = 0; index < temp.length; index++) {
for (int i = index+1; i < temp.length; i++) {
if (temp[i].length() > temp[index].length()) {
String word2 = temp[i];
temp[i] = temp[index];
temp[index] = word2;
}
}
System.out.println(temp[index] +" " +temp[index].length());
}
}

Is This Answer Correct ?    28 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a boolean output?

728


How do I type unicode?

736


Differentiate between the constructors and methods in java?

734


Objects or references which of them gets garbage collected?

733


What is the difference between compiler and jvm?

751


Can abstract class have private constructor?

717


What is an example of a conditional statement?

787


What is the default access specifier for variables and methods of a class?

852


why using interface interface ?

1774


How do I find and replace in word?

739


What is the difference between post and put?

775


What are the types of methodology?

776


How can we avoid including a header more than once?

801


Can a source file contain more than one class declaration?

727


Define iterator and methods in iterator?

750