Make a basic Java program called Reverser according to the following guidelines.
ID: 3671734 • Letter: M
Question
Make a basic Java program called Reverser according to the following guidelines.
The program prompts the user for two words (strings) from the command line and thenprints the words in reverse order, using one or more for loops to 'walk through' the strings.
For example, if the user enters "supposedly fantastic" your program should print "citsatnaf yldesoppus"(without the quotation marks).Remember to use one or more for loops
Explanation / Answer
import java.util.*; class ReverseString { public static void main(String args[]) { String original, reverse = ""; Scanner in = new Scanner(System.in); System.out.println("Enter a string to reverse"); original = in.nextLine(); int length = original.length(); for ( int i = length - 1 ; i >= 0 ; i-- ) reverse = reverse + original.charAt(i); System.out.println("Reverse of entered string is: "+reverse); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.