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


Please Help Members By Posting Answers For Below Questions

Explain what is encapsulation?

598


Define array. Tell me about 2-D array.

580


How can we pass argument to a function by reference instead of pass by value?

580


EDS (Electronic Data Systems India Pvt Ltd) at Chennai on 16-12-2006.

8612


what is thread in Java ?

618






What is yield () in java?

478


How to do encapsulation in java?

568


How many bits is a double?

524


Explain the difference between jvm and jre?

552


What are accessor methods in java?

546


What are the 4 versions of java?

552


Can a final method be overloaded?

503


Explain the private field modifier?

604


why not override thread to make a runnable? : Java thread

551


Can we define private and protected modifiers for the members in interfaces?

530