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 finalize()? Is finalize() similar to a destructor?

534


What are the types of web technologies?

518


What is final keyword in java?

547


According to java operator precedence, which operator is considered to be with highest precedence?

593


Differentiate between a class and an object.

558






How does split work in java?

528


What is command line argument

702


What do you understand by access specifiers in Java?

581


Can we assign null to double in java?

542


How can you set an applet’s height and width as a percentage?

506


What does main method?

554


What is mysql driver class name?

547


What is the method in java?

588


When is the finalize() called? What is the purpose of finalization?

577


Can constructor return value?

505