Exercise
Number repeated
Objetive
Write a Visual Basic (VB.Net) program that asks the user for a number and a quantity, and displays that number repeated as many times as the user has specified. Here's an example:
Enter a number: 4
Enter a quantity: 5
44444
You must display it three times: first using "while", then "do-while" and finally "for".
Code
' Import the System namespace to use Console classImports System
Public Class exercise29
Public Shared Sub Main()
Dim num, amount As Integer
Dim i As Integer
Console.Write("Enter a number: ")
num = Convert.ToInt32(Console.ReadLine())
Console.Write("Enter an amount: ")
amount = Convert.ToInt32(Console.ReadLine())
For i = 0 To amount - 1
Console.Write(num)
Next
Console.WriteLine()
i = 0
While i < amount
Console.Write(num)
i += 1
End While
Console.WriteLine()
i = 0
Do
Console.Write(num)
i += 1
Loop While i < amount
End Sub
End Class