{"id":1388,"date":"2022-03-03T19:16:19","date_gmt":"2022-03-03T19:16:19","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1388"},"modified":"2022-03-03T19:16:19","modified_gmt":"2022-03-03T19:16:19","slug":"program-to-reverse-words-in-a-string","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/program-to-reverse-words-in-a-string\/","title":{"rendered":"Program to reverse words in a String"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">&nbsp;Program to reverse every word in a String using methods<\/h2>\n\n\n\n<p>In this Program, we first split the given string into substrings using split() method. The substrings are stored in an String array&nbsp;<code>words<\/code>. The program then reverse each word of the substring using a reverse for loop.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Example\n{\n   public void reverseWordInMyString(String str)\n   {\n\t\/* The split() method of String class splits\n\t * a string in several strings based on the\n\t * delimiter passed as an argument to it\n\t *\/\n\tString&#91;] words = str.split(\" \");\n\tString reversedString = \"\";\n\tfor (int i = 0; i &lt; words.length; i++)\n        {\n           String word = words&#91;i]; \n           String reverseWord = \"\";\n           for (int j = word.length()-1; j &gt;= 0; j--) \n\t   {\n\t\t\/* The charAt() function returns the character\n\t\t * at the given position in a string\n\t\t *\/\n\t\treverseWord = reverseWord + word.charAt(j);\n\t   }\n\t   reversedString = reversedString + reverseWord + \" \";\n\t}\n\tSystem.out.println(str);\n\tSystem.out.println(reversedString);\n   }\n   public static void main(String&#91;] args) \n   {\n\tExample obj = new Example();\n\tobj.reverseWordInMyString(\"Welcome to BeginnersBook\");\n\tobj.reverseWordInMyString(\"This is an easy Java Program\");\n   }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Welcome to BeginnersBook\nemocleW ot kooBsrennigeB \nThis is an easy Java Program\nsihT si na ysae avaJ margorP<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;Program to reverse every word in a String using methods In this Program, we first split the given string into substrings using split() method. The substrings are stored in an String array&nbsp;words. The program then reverse each word of the substring using a reverse for loop. Output:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[385],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1388"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1388"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1388\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}