{"id":385,"date":"2018-09-03T12:58:04","date_gmt":"2018-09-03T12:58:04","guid":{"rendered":"http:\/\/www.vsit.in\/vsit-blog\/?p=385"},"modified":"2018-12-13T09:41:28","modified_gmt":"2018-12-13T09:41:28","slug":"find-longest-word-in-a-sentence-in-java","status":"publish","type":"post","link":"https:\/\/www.vsit.in\/vsit-blog\/find-longest-word-in-a-sentence-in-java\/","title":{"rendered":"Find Longest Word in a Sentence in Java"},"content":{"rendered":"<p>You can<strong> find Longest word in a sentence in java.\u00a0<\/strong>This is the most famous question of interviewer to <strong>find longest word in a sentence<\/strong>, Here i am giving java code to <strong>find longest word<\/strong>. In this java example we are using JOptionPane.showInputDialog(&#8220;&#8212;&#8220;), method of javax.swing package to accept input using dialog box. This technique of find longest word can implements in any programming language.<br \/>\n<code><\/p>\n<pre>\r\n\/\/ Find Longest Word in a sentence in java\r\nimport javax.swing.*;\r\nclass LongStr\r\n{\r\npublic static void main(String arg[])\r\n{\r\nString name=JOptionPane.showInputDialog(\"Enter a sentence\");\r\nname+=\" \";\r\nString str=\"\",lword=\"\";\r\nfor(int i=0;i &lt; name.length();i++)\r\n{\r\n        str+=name.charAt(i);\r\n        if(name.charAt(i)==' ')\r\n        {\r\n\t\tif(str.length() &gt; lword.length())\r\n\t\t{\r\n\t\t\tlword=str;\t\r\n\t\t}\r\n\tstr=\"\";\r\n\t}\r\n}\r\nSystem.out.println(\"Longest Word in a Sentence  : \"+lword);\r\n}\r\n}\r\n\r\n<\/pre>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can find Longest word in a sentence in java.\u00a0This is the most famous question of interviewer to find longest [&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,4],"tags":[],"class_list":["post-385","post","type-post","status-publish","format-standard","hentry","category-j2ee-training","category-java"],"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":"You can find Longest word in a sentence in java.\u00a0This is the most famous question of interviewer to find longest [&hellip;]","_links":{"self":[{"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/posts\/385","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=385"}],"version-history":[{"count":5,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/posts\/385\/revisions"}],"predecessor-version":[{"id":392,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/posts\/385\/revisions\/392"}],"wp:attachment":[{"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/media?parent=385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/categories?post=385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/tags?post=385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}