Ejercicio
Formatos
Objetivo
Escriba un programa en Visual Basic para pedir al usuario un número y muestre ir cuatro veces seguidas, separadas con espacios en blanco y, a continuación, cuatro veces en la fila siguiente, sin separación. Debe hacerlo dos veces: primero usando Console.Write y luego usando {0}.
Código
' 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