{"id":121,"date":"2016-01-16T14:42:50","date_gmt":"2016-01-16T14:42:50","guid":{"rendered":"http:\/\/www.vsit.in\/vsit-blog\/?p=121"},"modified":"2016-09-06T11:56:30","modified_gmt":"2016-09-06T11:56:30","slug":"count-number-of-words-in-a-string-in-java","status":"publish","type":"post","link":"https:\/\/www.vsit.in\/vsit-blog\/count-number-of-words-in-a-string-in-java\/","title":{"rendered":"Count Number of Words in a String in Java"},"content":{"rendered":"<p>import java.util.*;<\/p>\n<p>class WordsCount<\/p>\n<p>{<\/p>\n<p>public static void main(String arg[])<\/p>\n<p>{<\/p>\n<p>int word=1;<\/p>\n<p>Scanner in=new Scanner(System.in);<\/p>\n<p>System.out.println(&#8220;Enter your sentence:[Try to ignore space at end]&#8221;);<\/p>\n<p>String str=in.nextLine();<\/p>\n<p>for(int i=0;i&lt;str.length();++i)<\/p>\n<p>{<\/p>\n<p>if(str.charAt(i)==&#8217; &#8216;)<\/p>\n<p>word++;<\/p>\n<p>}<\/p>\n<p>System.out.println(&#8220;Number of words=&#8221;+word);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>import java.util.*; class WordsCount { public static void main(String arg[]) { int word=1; Scanner in=new Scanner(System.in); System.out.println(&#8220;Enter your sentence:[Try to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1,12,4,15,14,13,17],"tags":[],"class_list":["post-121","post","type-post","status-publish","format-standard","hentry","category-j2ee-training","category-janakpuri","category-java","category-tilak-nagar","category-uttam-nagar","category-vikaspuri","category-west-delhi"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"shubhranshu shekhar","author_link":"https:\/\/www.vsit.in\/vsit-blog\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"import java.util.*; class WordsCount { public static void main(String arg[]) { int word=1; Scanner in=new Scanner(System.in); System.out.println(&#8220;Enter your sentence:[Try to [&hellip;]","_links":{"self":[{"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/posts\/121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/comments?post=121"}],"version-history":[{"count":4,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/posts\/121\/revisions"}],"predecessor-version":[{"id":125,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/posts\/121\/revisions\/125"}],"wp:attachment":[{"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/media?parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/categories?post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/tags?post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}