Formats Learn programming Visual Basic (VB.net)



Lesson:

First contact with Visual Basic (VB.net)


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:

Imports System
Public Class exercise12
    Public Shared Sub Main()
        Dim n As Integer
        Console.WriteLine("Enter a digit: ")
        n = Convert.ToInt32(Console.ReadLine())
        Console.Write(n)
        Console.Write(" ")
        Console.Write(n)
        Console.Write(" ")
        Console.Write(n)
        Console.Write(" ")
        Console.Write(n)
        Console.WriteLine()
        Console.Write(n)
        Console.Write(n)
        Console.Write(n)
        Console.WriteLine(n)
        Console.WriteLine()
        Console.WriteLine("{0} {0} {0} {0}", n)
        Console.WriteLine("{0}{0}{0}{0}", n)
    End Sub
End Class



Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.