gpt4 book ai didi

c# - 使用递归获取整数的位数

转载 作者:太空宇宙 更新时间:2023-11-03 11:16:25 25 4
gpt4 key购买 nike

<分区>

我正在编写一个函数,该函数应该使用递归来获取整数中的位数,例如236有3个数字。到目前为止我有这个,但它没有用。另外,那里有递归的真正好的解释吗?

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(getDigits(5428, 0));
Console.ReadLine();
}

public static int getDigits(int digits, int i)
{
if (digits != 0)
{
i++;
getDigits(digits/10, i);
}

return i;
}
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com