Menu Bar

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, 17 January 2017

Write a java program to count the number of words in a String ?


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
public class CountWords {

 public static void getCount(String str){
  System.out.println("INPUT STRING : "+str);
  String[] words = str.split(" ");
  System.out.println("TOTAL WORDS IN STRING : "+words.length);
 }
 public static void main(String[] args) {
  CountWords.getCount("String is Immutable in Java");
 }

}

Output:

INPUT STRING : String is Immutable in Java
TOTAL WORDS IN STRING : 5


      
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



Share this Blog with yours Friends !!

No comments:

Post a Comment