Exercise
Square
Objetive
Write a Visual Basic (VB.Net) program that prompts the user to enter a number and a width, and displays a square of that width, using that number for the inner symbol, as shown in this example:
Enter a number: 4
Enter the desired width: 3
444
444
444
Code
' Importing necessary namespaces
Imports System
Public Class Program
Public Shared Sub Main()
' Declare variables for the number and width
Console.Write("Enter a number: ")
Dim number As Integer = Convert.ToInt32(Console.ReadLine()) ' Read the number from the user
Console.Write("Enter the desired width: ")
Dim width As Integer = Convert.ToInt32(Console.ReadLine()) ' Read the width from the user
' Loop to display the square with the given width
For i As Integer = 0 To width - 1
' Loop to display the number in each row
For j As Integer = 0 To width - 1
Console.Write(number) ' Print the number without a newline
Next
Console.WriteLine() ' Move to the next line after each row
Next
End Sub
End Class