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
Why string is a class?
How many classes can any class inherit java?
Why is whitespace important?
How do you escape json?
What do you mean by an interface in java?
What is a copy constructor in java?
What are runtime exceptions?
What is private public protected in java?
What are the 8 data types in java?
Explain the scope or life time of class variables or static variables?
What is java util hashmap?
What is foreach loop in java?
Do extraneous variables affect validity?
Explain the difference between abstract classes and interfaces in java?
How do you use compareto?