Write a java program to count the number of words present in a string?
Answer / Pranay Kumar Suryavanshi
Here is a simple Java program that counts the number of words in a given string. The program splits the string by white spaces and then returns the length of the resulting array.nn```javanpublic class WordCounter {n public static void main(String[] args) {n String str = "This is a sample string";n String[] words = str.split(" ");n System.out.println("Number of words: " + words.length);n }n}n```
| Is This Answer Correct ? | 0 Yes | 0 No |
What is the file type?
is it possible to instantiate the math class?
In java, how many ways you can take input from the console?
What is thin driver and thick driver. why it is called so?
What is a finally block? Is there a case when finally will not execute?
What is double data type?
What is the difference between jfc & wfc?
Name the package that always imported by default?
What is a pattern what is an anti pattern?
What does pointer mean?
What is the use of list in java?
What is Applet Stub Interface ?