Exercise
Formats
Objetive
Write a Visual Basic (VB.Net) program to ask the user for a number and display it four times in a row, separated with blank spaces, and then four times in the next row, with no separation. You must do it two times: first using Console.Write and then using {0}.
Example:
Enter a number: 3
3 3 3 3
3333
3 3 3 3
3333
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 number
Console.Write("Enter a number: ")
' Read the user's input and convert it to an integer
Dim number As Integer = Convert.ToInt32(Console.ReadLine())
' Print the number four times in a row, separated by spaces using Console.Write
Console.Write(number & " " & number & " " & number & " " & number)
Console.WriteLine() ' Move to the next line
' Print the number four times in a row, without any separation using Console.Write
Console.Write(number.ToString() & number.ToString() & number.ToString() & number.ToString())
Console.WriteLine() ' Move to the next line
' Print the number four times in a row, separated by spaces using {0} format
Console.WriteLine("{0} {0} {0} {0}", number)
' Print the number four times in a row, without any separation using {0} format
Console.WriteLine("{0}{0}{0}{0}", number)
End Sub
End Class