Rectangle V3 Learn programming Visual Basic (VB.net)

Lesson:

Arrays, Structures and Strings


Exercise:

Rectangle V3


Objetive:

Write a Visual Basic (VB.net) program to ask the user for his/her name and a size, and display a hollow rectangle with it:

Enter your name: Yo
Enter size: 4
YoYoYoYo
Yo____Yo
Yo____Yo
YoYoYoYo

(note: the underscores _ should not be displayed on screen; you program should display blank spaces inside the rectangle)


Code:

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

        For row = 0 To height - 1

            For column = 0 To width - 1
                Console.Write(n)
            Next

            Console.WriteLine()
        Next
    End Sub
End Class

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