中易网

C#如何输出

答案:5  悬赏:30  
解决时间 2021-02-01 15:31
*
**
***
****
最佳答案
for(int i=1;i<=4;i++)
{
for(int j=0;j {
Console.Write("*");
}
Console.WriteLine();
}
全部回答
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { for (int i = 0; i < 4; i++) { for (int m = 0; m < i+1; m++) { Console.Write("*"); } Console.WriteLine(); } Console.ReadLine(); } } }
已经把程序精简到只有一个FOR循环了 貌似楼主在另外一个区域也发了一个一模一样的问题,哈哈.路过..正好看到 static void Main(string[] args) { for (int a = 1; a <= 4; a++) { Console.WriteLine(new string('*',a)); } }
这个基本完整的程序,有选择是否实心,而且有差错功能···你自己看吧··· public static void Main(string[] args) { int w=0; char c; Console.WriteLine("输入正三角形的边长:"); try { w = Int32.Parse(Console.ReadLine()); } catch (FormatException fe) { Console.WriteLine(fe.Message); } Console.WriteLine("是否实心?(Y/N)"); try { c = (char)Console.Read(); if (c != 'Y' && c != 'y' && c != 'N' && c != 'n') throw new FormatException("输入格式错误"); } catch (Exception e) { Console.WriteLine(e.Message); return; } for (int i = 0; i < w; i++) { for (int j = 0; j <= i; j++) { if ((c == 'N' || c == 'n')&&i!=0&&i!=w-1) { Console.Write("*"); for(int k=j+1;k
  • 4楼网友:冷眼_看世界
  • 2021-02-01 13:21
console.WriteLine("*\n**\n***\n****"); 这个才是最简的吧.没必要用什么循环占资源吧...
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯