COMP2247 - Algorithms and Data Structures

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Recursion Factorial Program Fibonacci Program Integer Power Program Tower of Hanoi Program Max Element Program Palindrome Program Reverse String Program Array Sum Program



ReverseString Program


Description

The program inputs a string and uses a recursive method to print the string in reverse order.

Associated Concepts:

Recursion

Algorithm:

main method:

Input a string

Call printReverse method with the input string as the argument

printReverse method definition:

If the input string has only one character, print it.

Otherwise

Print the last character

Call printReverse() method recursively with the argument of the substring from 0 to the second last character

Source Code



Sample Run



Video