c# - 有没有可以用多个符号表示为金字塔的求和函数
问题描述
我想问如何在字符串中用符号“*”表示 int 中的数量,使其在命令行中看起来像金字塔
例如
int a = int.parse(Console.ReadLine())
a = 1 then Console.WriteLine("*")
a = 2 then write"**"
如此继续 3=*** 4=****
谢谢
解决方案
我发现最好的方法是使用函数“for”两次,使用函数“new string”。这将在控制台中创建一个金字塔形状。
例如
int a = int.parse(Console.ReadLine())
For(int b=0;b<a;b++)
{
Console.Write new string('*',b)
Console.WriteLine("*")
}
For(int c=a;b>0;b--)
{
Console.Write new string('*',c)
Console.WriteLine("*")
}
推荐阅读
- oracle - 在 Oracle S9(15)V9(2) 中需要特定的数字格式
- reactjs - 自定义挂钩 SetInterval
- reactjs - React 路由器更改 url 但不更改页面加载
- c++ - 自动运行程序 c++
- java - Android App 未通过 Firebase FCM 收到推送通知
- f# - 在 Dapper 中获取 QueryMultipleAsync 以使用 F#
- python - 有没有办法用pynput在python中引用退格?
- python - 如何将 pandas 数据框的元素组合为坐标对?
- java - 如果日期无效,我如何让 java 日期不会自动转换
- php - wordpress 按 acf 字段中保存的值排序帖子