{"id":358,"date":"2018-04-05T10:07:27","date_gmt":"2018-04-05T10:07:27","guid":{"rendered":"http:\/\/www.vsit.in\/vsit-blog\/?p=358"},"modified":"2018-04-06T07:21:36","modified_gmt":"2018-04-06T07:21:36","slug":"java-program-to-reverse-words-in-a-sentence","status":"publish","type":"post","link":"https:\/\/www.vsit.in\/vsit-blog\/java-program-to-reverse-words-in-a-sentence\/","title":{"rendered":"Java Program to Reverse Words in a Sentence"},"content":{"rendered":"<p><strong>Java Program to Reverse Words in a Sentence<\/strong> : In Java we can reverse each word in a sentence using <strong>String Methods<\/strong>. In this program, we are using\u00a0<strong>JOptionPane.showInputDialog()<\/strong> method of <strong>javax.swing<\/strong> package to accept input from user. In java inputs are String by default.<\/p>\n<p><code><\/code><\/p>\n<pre>\/\/Java Programe to Reverse Words in a Sentence\r\n\r\nimport javax.swing.*;\r\nclass StrRev\r\n{\r\npublic static void main(String arg[])\r\n{\r\nString name=JOptionPane.showInputDialog(\"Enter a sentence\");\r\nname+=\" \";\r\nint i,k;\r\nString revstr=\"\",str=\"\";\r\nfor(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               for(k=str.length()-1;k&gt;=0;k--)\r\n\t       {\r\n\t\t       revstr+=str.charAt(k);\r\n\t       }\r\n\tstr=\"\";\r\n\t}\r\n}\r\nSystem.out.println(\"Revserse of Sentence is : \"+revstr);\r\n}\r\n}\r\n\r\nInput  : THIS IS EXAMPLE\r\nOutput : SIHT SI ELPMAXE\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java Program to Reverse Words in a Sentence : In Java we can reverse each word in a sentence using [&hellip;]<\/p>\n","protected":false},"author":2,"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":[18],"class_list":["post-358","post","type-post","status-publish","format-standard","hentry","category-j2ee-training","category-java","tag-java-training"],"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\/shekhar\/"},"uagb_comment_info":0,"uagb_excerpt":"Java Program to Reverse Words in a Sentence : In Java we can reverse each word in a sentence using [&hellip;]","_links":{"self":[{"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/posts\/358","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\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/comments?post=358"}],"version-history":[{"count":3,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/posts\/358\/revisions"}],"predecessor-version":[{"id":361,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/posts\/358\/revisions\/361"}],"wp:attachment":[{"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/media?parent=358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/categories?post=358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vsit.in\/vsit-blog\/wp-json\/wp\/v2\/tags?post=358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}