Answer the question
In order to leave comments, you need to log in
How does this recursive method work?
Explain in detail how recursion works in this program:
using System;
class RevStr
{
public void DisplayRev(string str)
{
if (str.Length > 0)
{
DisplayRev(str.Substring(1, str.Length - 1));
}
else
return;
Console.Write(str[0]);
}
}
class RevStrDemo
{
static void Main()
{
string s = "Это тест";
RevStr rsOb = new RevStr();
Console.WriteLine("Исходная строка: " + s);
Console.Write("Перевернутая строка: ");
rsOb.DisplayRev(s);
Console.WriteLine();
}
}
Answer the question
In order to leave comments, you need to log in
"ABCD" → "BCD" → "CD" → "D" → "" ↘
print A ← print B ← print C ← print D
When using the debugger, everything becomes clear.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question