Write a java program to get a string of words and print the numbers of each word count in descending order
Answer Posted / ruchira
import java.util.StringTokenizer;
public class NumberOfWords {
/**
* to get a string of words and print the numbers of
each word count in descending order
*/
public static void main(String[] args) {
String str = "Save water";
System.out.println(str);
StringTokenizer st = new
StringTokenizer(str," ");
int i = 0;
i=st.countTokens();
while (i>0)
{
System.out.println(i);
i --;
}
}
}
| Is This Answer Correct ? | 12 Yes | 3 No |
Post New Answer View All Answers
What is java util collection?
What are green threads in java?
How do you pass by reference?
How can we make copy of a java object?
Can we override constructors in java?
What is the list interface in java programming?
What are the kinds of polymorphism?
How do you define a singleton class?
What is style and indentation?
What are scalar data types?
What is java string pool?
What's the default access specifier for variables and methods of a class?
Write a program to find maximum and minimum number in array?
What is an infinite loop in java? Explain with an example.
Can we extend private class in java?