Question: Printing a string backwards can be done either iteratively or recursively. To do it recursively, think of the following specification: If S contains any characters
Printing a string backwards can be done either iteratively or recursively. To do it
recursively, think of the following specification:
If contains any characters ie is not the empty string
print the last character in S
print backwards, where is without its last character
File Backwards.java contains a program that prompts the user for a string, then calls
method printBackwards to print the string backwards. Save this file to your directory and
fill in the code for printBackwards using the recursive strategy outlined above.
Backwards.java
Uses a recursive method to print a string backwards.
import java.util.Scanner;
public class Backwards
Reads a string from the user and prints it backwards.
public static void mainString args
String msg;
Scanner scan new ScannerSystemin;
System.out.printEnter a string: ;
msg scan.nextLine;
System.out.println
The string backwards: ;
printBackwardsmsg;
System.out.println;
Takes a string and recursively prints it backwards.
public static void printBackwardsString s
Fill in code
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
