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

Why string is a class?

730


How many classes can any class inherit java?

731


Why is whitespace important?

783


How do you escape json?

765


What do you mean by an interface in java?

767


What is a copy constructor in java?

818


What are runtime exceptions?

895


What is private public protected in java?

809


What are the 8 data types in java?

748


Explain the scope or life time of class variables or static variables?

739


What is java util hashmap?

734


What is foreach loop in java?

756


Do extraneous variables affect validity?

705


Explain the difference between abstract classes and interfaces in java?

842


How do you use compareto?

719