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 do you mean by light weight and heavy weight components?

559


How do you declare an array in java?

523


What is overriding in java?

522


What do bitwise operators do?

529


What is meant by interface?

565






What is runtime locatable code?

869


What is a local block?

640


What are the different types of java?

561


How is garbage collection controlled?

736


What is constructor in java ?

636


Can an object subclass another object?

557


Is void a data type in java?

526


Is set ordered in java?

572


How can you read content from file in java?

599


What does @param args mean in java?

556