Hollow rectangle Learn programming Visual Basic (VB.net)

Lesson:

Flow Control


Exercise:

Hollow rectangle 16


Objetive:

Write a program which asks for a symbol, a width and a height and displays a hollow rectangle of that width and that height, using that number for the outer symbol, as in this example:

Enter a symbol: 4
Enter the desired width: 3
Enter the desired height: 5

444
4 4
4 4
4 4
444


Code:

Imports System
Public Class exercise42
    Public Shared Sub Main()
        Dim row, column As Integer
        Console.Write("Enter a symbol: ")
        Dim symbol As Integer = Convert.ToInt32(Console.ReadLine())
        Console.Write("Enter the desired width: ")
        Dim width As Integer = Convert.ToInt32(Console.ReadLine())
        Console.Write("Enter the desired height: ")
        Dim height As Integer = Convert.ToInt32(Console.ReadLine())
        Console.WriteLine()

        For row = 1 To height

            For column = 1 To width

                If (row = 1) OrElse (row = height) Then
                    Console.Write(symbol)
                Else

                    If (column = 1) OrElse (column = width) Then
                        Console.Write(symbol)
                    Else
                        Console.Write(" ")
                    End If
                End If
            Next

            Console.WriteLine()
        Next
    End Sub
End Class