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 are the access modifiers in java?
Does windows 10 need java?
Write code of any action class?
How do you reverse a string in java without using string buffer?
what is inner class in java?
What’s the difference between the methods sleep() and wait()?
What is an i/o filter?
What is the difference between @before and @beforeclass annotation?
What are the main differences between the java platform and other platforms?
How to access arraylist elements in java?
What are inbuilt functions?
What is the protected method modifier?
Explain the features of java?
Describe 2 different ways to concatenate two strings.
Can we access instance variables within static methods ?