回 帖 发 新 帖 刷新版面

主题:输入一个数 然后输出正方形[用控制台程序] 用*显示的比如 输入2就显示

VB.NET输入一个数 然后输出正方形[用控制台程序] 用*显示的比如 输入2就显示
**
**
输入3就是
***
***
***
输入4就是
****
****
****
****
有人能教教我吗?

回复列表 (共4个回复)

沙发

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i, i1, i2 As Integer
        Dim ss As String
        i = CInt(InputBox("请输入一个整数", "Input", "2"))
        i1 = i
        For i1 = 1 To i
            ss = ""
            For i2 = 1 To i
                ss = ss & "*"
            Next
            Console.WriteLine(ss)
        Next
        Console.ReadLine()
    End Sub

板凳

我试了不对啊

3 楼

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i, j, m As Integer
        Dim ss As String
        m = CInt(InputBox("请输入一个整数", "Input", "2"))
        For i = 1 To m
            For j = 1 To m
                ss &= "*"
            Next
            ss &= vbNewLine
        Next
        TextBox1.Text = ss ’这里TextBox1.Multiline = True
    End Sub

4 楼

不好意思,米看到是用控制台程序,那就改成:
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
        Dim i, j, m As Integer
        Dim ss As String
        m = CInt(InputBox("请输入一个整数", "Input", "2"))
        For i = 1 To m
            For j = 1 To m
                ss &= "*"
            Next
            ss &= vbNewLine
        Next
        Console.WriteLine(ss)
        Console.ReadLine()
    End Sub

我来回复

您尚未登录,请登录后再回复。点此登录或注册