*
**
***
****
C#如何输出
答案:5 悬赏:30
解决时间 2021-02-01 15:31
- 提问者网友:乏味沐染
- 2021-02-01 11:49
最佳答案
- 二级知识专家网友:输掉的尊严
- 2021-02-01 13:07
for(int i=1;i<=4;i++)
{
for(int j=0;j {
Console.Write("*");
}
Console.WriteLine();
}
{
for(int j=0;j {
Console.Write("*");
}
Console.WriteLine();
}
全部回答
- 1楼网友:何必打扰
- 2021-02-01 15:44
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();
}
}
}
- 2楼网友:甜野猫
- 2021-02-01 14:31
已经把程序精简到只有一个FOR循环了
貌似楼主在另外一个区域也发了一个一模一样的问题,哈哈.路过..正好看到
static void Main(string[] args)
{
for (int a = 1; a <= 4; a++) {
Console.WriteLine(new string('*',a));
}
}
- 3楼网友:duile
- 2021-02-01 14:13
这个基本完整的程序,有选择是否实心,而且有差错功能···你自己看吧···
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****");
这个才是最简的吧.没必要用什么循环占资源吧...
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯