Exercise
Rectangle
Objetive
Write a Visual Basic (VB.Net) program to ask the user for a number and then display a rectangle 3 columns wide and 5 rows tall using that digit. For example:
Enter a digit: 3
333
3 3
3 3
3 3
333
Code
' Import the System namespace to use Console class
Imports System
Public Class Program
' Main subroutine, entry point of the program
Public Shared Sub Main()
' Ask the user to input a digit
Console.Write("Enter a digit: ")
' Read the user's input and convert it to an integer
Dim digit As Integer = Convert.ToInt32(Console.ReadLine())
' Print the top row of the rectangle
Console.WriteLine("{0}{0}{0}", digit) ' 3 columns wide
' Print the middle rows of the rectangle
For i As Integer = 0 To 2 ' 3 rows in the middle
Console.WriteLine("{0} {0}", digit) ' 3 columns with space in between
Next
' Print the bottom row of the rectangle
Console.WriteLine("{0}{0}{0}", digit) ' 3 columns wide
End Sub
End Class