Reverse a string in java word by word

// Reverse a string in java word by word
import java.util.Scanner;
public class ReverseStringWordByWord 
{
   public static void main(String[] args) 
   {
      String strWord = "";
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter a string: ");
      String strGiven = sc.nextLine();     
      char[] chArray = strGiven.toCharArray();
      System.out.println("Reversed string word by word: ");
      for(int a = 0; a < (chArray.length); a++)
      {
         if(chArray[a] != ' ')
         {
            strWord = strWord + chArray[a];
         }
         else
         {
            for(int b = strWord.length(); b > 0; b--)
            {
               System.out.println(strWord.charAt(b - 1));       
            }
            System.out.print(" ");
            strWord = "";
         }
      }
      for(int b = strWord.length(); b > 0; b--)
      {
         System.out.println(strWord.charAt(b - 1));       
      }
      sc.close();
   }
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
reverse each word in a given string in java reverse string word wise java how to reverse a string in java word by word reverse each word of string in java given a string reverse each word in the sentence in java reverse java string word Program to reverse every word in a String and reverse the string java reverse each word in a string in java java string reverse word order inverse word order in string java how to write a word backwards in java reverse a string words by word using recursion java reverse string in java word wise reverse string word wise in java how to reverse a string word by word in java string reverse word by word in java java program to reverse every word in a string reverse a word java method reverse a word java write a function to reverse a string word wise in java reverse words in a given string in java how to reverse word in java how to reverse a word in java reverse a string word by word in java java program to reverse each word in string reverse each word in a string java reverse every other word in a java string java what is reversed word Given a string, reverse each word in the sentence using java write a java program to reverse a word how to make a word backwards java reverse the word in string in java how to reverse word by word in java reverse the strign word by word java java reverse word string reverse by words in java allintitle:Reverse a string in java word by word reverse a string word wise in java reverse word in a give sentence in java reverse a word in java reverse string word by word in java reverse every word in a string in java reverse word in java how to reverse string in java each word WAP in java to reverse a string by word. reverse words in a string java Reverse a string in java word by word
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source