Triangle, NorthEast Learn programming Visual Basic (VB.net)

Lesson:

Basic Data Types


Exercise:

Triangle, NorthEast 14


Objetive:

Write a Visual Basic (VB.net) program which asks for a width, and displays a triangle like this one:

Enter the desired width: 5

*****
_****
__***
___**
____*


Code:

Imports System
Public Class exercise62
    Public Shared Sub Main()
        Dim width, height As Integer
        Dim row, column As Integer
        Dim max As Integer
        Console.Write("Enter the desired width: ")
        height = Convert.ToInt32(Console.ReadLine())
        width = 0
        max = height

        For row = 0 To height - 1

            For column = 0 To width - 1
                Console.Write(" ")
            Next

            For asterisks As Integer = 0 To max - 1
                Console.Write("*")
            Next

            Console.WriteLine()
            width += 1
            max -= 1
        Next
    End Sub
End Class