Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:24:28+00:00 2026-06-13T11:24:28+00:00

this was the solution to my homework and the purpose was to reverse each

  • 0

this was the solution to my homework and the purpose was to reverse each word in a string based on user inputting a sentence. I have completed this on my own, but I’m just wondering how the iterator worked in this piece of code. I don’t understand the delcaration of tempword = “”; and how he printed out each word delimited by spaces.

import java.util.Scanner;

public class StringReverser
{
    public static void main(String args[])
    {
        String sentence;
        String word;
        String tempWord = "";

        Scanner scan = new Scanner(System.in);
        Scanner wordScan;

        System.out.print("Enter a sentence: ");
        sentence = scan.nextLine();

        wordScan = new Scanner(sentence);

        while(wordScan.hasNext())
        {
            word = wordScan.next();

            for(int numLetters = word.length() - 1; numLetters >= 0; numLetters--)
                tempWord += word.charAt(numLetters);

            System.out.print(tempWord + " ");
            tempWord = "";
        }
        System.out.println();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:24:29+00:00Added an answer on June 13, 2026 at 11:24 am

    this bit adds in the spaces

    System.out.print(tempWord + " ");
    

    this bit reverses it

    for(int numLetters = word.length() - 1; numLetters >= 0; numLetters--)
                tempWord += word.charAt(numLetters);
    

    this bit sets it up for the next word

    tempWord = "";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have this string: ABCDEFGH And you want to reverse it so that
I searched for an implementation of std::map runtime ordering and have found this solution:
I am stumped on this homework problem. I think I have the right answer
This is not homework, I don't have money for school so I am teaching
I solved my homework problem, I used recursion tree. But solution says that this
For my homework I have to test for several large matrices using this Conjugate
I have this homework, I have only 1 problem, and I don't know the
DISCLAIMER: This question is related to homework. I am not expecting a solution, but
is this solution possible in asp.net dragging picturebox inside winform on runtime i just
This was just what I was thinking for this solution and I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.