amespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 1; i <= 4; i++)//表示行数
{
for (int j = 1; j <=4 - i; j++)//星星前面的空格数
textBox1.Text += " ";
for (int k = 0; k < 2 * i - 1;k++ )//星星个数
textBox1.Text += "*";
textBox1.Text += Environment.NewLine;//换行
}
}
}
这个是所有代码
我是用一个Button的点击事件触发的,在进行此操作前记得设置textBox的MultiLine属性为true
for (int i = 1; i <= num; i++)
{
for (int j = 1; j <=i; j++)
{
System.out.print("*")
}
System.out.println();
}
用控制台写。兄弟用窗体时写不出来的啊
StringBuilder sb = new StringBuilder();
for(int i=0;i<4;i++)
{
for(int j=0;j {
sb.Append("*");
}
sb.Append("\r\n");
}
TextBox.Text = sb.ToString();