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
Explain what is encapsulation?
Define array. Tell me about 2-D array.
How can we pass argument to a function by reference instead of pass by value?
EDS (Electronic Data Systems India Pvt Ltd) at Chennai on 16-12-2006.
what is thread in Java ?
What is yield () in java?
How to do encapsulation in java?
How many bits is a double?
Explain the difference between jvm and jre?
What are accessor methods in java?
What are the 4 versions of java?
Can a final method be overloaded?
Explain the private field modifier?
why not override thread to make a runnable? : Java thread
Can we define private and protected modifiers for the members in interfaces?