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
Which class is the superclass for all the classes?
Can list be null in java?
Can we inherit inner class?
What is string data type?
What is a module function?
What are the main uses of java?
how to write a program for sending mails between client and server
What is an object’s lock and which object’s have locks?
Why singleton class is used in java?
How does hashmap work in java ?
What is complexity and its types?
Can a abstract class be declared final?
How objects of a class are created if no constructor is defined in the class?
What are the principle concepts of oops?
How do you write a scanner class in java?