Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program that uses a method which reverses the characters in a String taken from user input. For example, if the user inputs

Write a Java program that uses a method which reverses the characters in a String taken from user input. For example, if the user inputs "The moon is made of green cheese", the output is "eseehc neerg fo edam si noom ehT"

main() should use a Scanner to take an input String, call the methods that reverses the input, and print out the result. Use Scanner's nextLine() method so that you can use Strings that contain whitespace.

The reverse method should take a String as its only parameter, create an empty StringBuilder, and loop through the characters in the String from last to first adding each to the StringBuilder. It should then return the StringBuilder. Note that for loops may use decrement operators (for example, for(int counter = 5; counter >= 0; counter--) is perfectly valid.) You will probably need the String method charAt(). Do not use StringBuilder's reverse() method.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions

Question

=+31-5 Explain how sensory memory works.

Answered: 1 week ago