1 回答

TA貢獻(xiàn)1772條經(jīng)驗 獲得超5個贊
我想,你要找的就是這個。用你的兩個處理能力。
static void Main(string[] args)
{
PrintStars(8, 0, 0);
}
static void PrintStars(int stars, int prefix, int suffix)
{
if(stars == 1)
{
PrintStarsToConsole(stars, prefix, suffix);
return;
}
var halfStars = stars >> 1;
PrintStars(halfStars, prefix + halfStars, suffix); // for n = 4: __**
PrintStarsToConsole(stars, prefix, suffix); // for n = 4: ****
PrintStars(halfStars, prefix, suffix + halfStars); // for n = 4: **__
}
static void PrintStarsToConsole(int stars, int prefix, int suffix)
{
Console.Write(new string(' ', prefix));
Console.Write(new string('*', stars));
Console.Write(new string(' ', suffix));
Console.WriteLine();
}
- 1 回答
- 0 關(guān)注
- 130 瀏覽
添加回答
舉報