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
Name some OOPS Concepts in Java?
What language is java written?
How many characters is 2 bytes?
What is stack example?
What is singleton pattern?
What are the types of arrays in java?
What is java and why do we need it? Explain
Java is Pass by Value or Pass by Reference?
What are the types of methods in java?
Can a private method of a superclass be declared within a subclass?
How to provide security in java
What is early binding and late binding in java?
What are packages in java?
What is singletonlist in java?
What is unmodifiable list in java?