在microsoft visual studio软件中,在页面上建一个按钮,在按钮中编写代码,使得按下按钮可以打印出图形
展开全部
写了个方法 Print(int row,char s) row是三角形的行数,char是用什么字符打印
protected void Button1_Click(object sender, EventArgs e)
{
Print(3, '*');
}
private void Print(int row, char s)
{
for (int j = 1; j <= row; j++)
{
for (int i = 1; i <= row*2 -1; i++)
{
if (j == 1)
{
if (i == row)
{ Response.Write(s); }
else
{ Response.Write(" "); }
}
else if (j == row)
{
Response.Write(s);
}
else
{
if (i == (row - (j - 1)) || i == row + (j - 1))
{ Response.Write(s); }
else
{ Response.Write(" "); }
}
}
Response.Write("<br>");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Print(3, '*');
}
private void Print(int row, char s)
{
for (int j = 1; j <= row; j++)
{
for (int i = 1; i <= row*2 -1; i++)
{
if (j == 1)
{
if (i == row)
{ Response.Write(s); }
else
{ Response.Write(" "); }
}
else if (j == row)
{
Response.Write(s);
}
else
{
if (i == (row - (j - 1)) || i == row + (j - 1))
{ Response.Write(s); }
else
{ Response.Write(" "); }
}
}
Response.Write("<br>");
}
}
追问
如果我要打印“空心等腰三角形”呢?怎么修改?
追答
这本来就是空心等腰三角形
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询