Hollow square Learn programming Visual Basic (VB.net)



Lesson:

Flow Control


Exercise:

Hollow square


Objetive:

Write a Visual Basic (VB.net) program that asks for a symbol and a width, and displays a hollow square of that width using that symbol for the outer border, as shown in this example:

Enter a symbol: 4
Enter the desired width: 3

444
4 4
444


Code:

Imports System
Public Class exercise39
    Public Shared Sub Main()
        Dim n As Integer
        Dim i, j As Integer
        Console.Write("Enter number for the border of the square: ")
        n = Convert.ToInt32(Console.ReadLine())
        Console.Write("Enter total: ")
        width = Convert.ToInt32(Console.ReadLine())
        i = 0

        While i
            Console.Write(n)
            i += 1
        End While

        Console.WriteLine()
        i = 0

        While i - 2
            Console.Write(n)
            j = 0

            While j - 2
                Console.Write(" ")
                j += 1
            End While

            Console.WriteLine(n)
            i += 1
        End While

        i = 0

        While i
            Console.Write(n)
            i += 1
        End While

        Console.WriteLine()
    End Sub
End Class



Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.