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
What do you mean by light weight and heavy weight components?
How do you declare an array in java?
What is overriding in java?
What do bitwise operators do?
What is meant by interface?
What is runtime locatable code?
What is a local block?
What are the different types of java?
How is garbage collection controlled?
What is constructor in java ?
Can an object subclass another object?
Is void a data type in java?
Is set ordered in java?
How can you read content from file in java?
What does @param args mean in java?