Sort data Learn programming Visual Basic (VB.net)

Lesson:

Arrays, Structures and Strings


Exercise:

Sort data


Objetive:

Create a Visual Basic (VB.net) program to ask the user for 10 integer numbers (from -1000 to 1000), sort them and display them sorted.


Code:

Imports System
Public Class exercise91
    Public Shared Sub Main()
        Dim total As Integer = 9
        Dim data As Integer() = New Integer(total - 1) {}
        Dim i, j, aux As Integer

        For i = 0 To total - 1
            Console.Write("Enter number {0}: ", i + 1)
            data(i) = Convert.ToInt32(Console.ReadLine())
        Next

        For i = 0 To total - 1 - 1

            For j = i + 1 To total - 1

                If data(i) > data(j) Then
                    aux = data(i)
                    data(i) = data(j)
                    data(j) = aux
                End If
            Next
        Next

        Console.Write("Sorted:")

        For Each valor As Integer In data
            Console.Write("{0} ", valor)
        Next
    End Sub
End Class

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