Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started