如何按升序顺序打印数字

时间:2016-01-22 02:49:39

标签: vb.net multithreading numbers

我有一个程序应该打印用户输入的数字,按顺序在两个不同的线程中上升和下降。我有线程设置,但我是一个初学者,我迷失了如何在各自的线程中按顺序打印数字。这就是我到目前为止所拥有的

Module Module1

  Sub Main()

    Dim A, B, C, D, E, F As String

    A = Console.ReadLine()

    B = Console.ReadLine()

    C = Console.ReadLine()

    D = Console.ReadLine()

    E = Console.ReadLine()

    F = Console.ReadLine()

    Dim Up As System.Threading.Thread = New Threading.Thread(AddressOf Ascending)

    'Setting Up as a thread

    Up.Start()

    Dim Down As System.Threading.Thread = New Threading.Thread(AddressOf Decending)

    Down.Start()

    Console.ReadKey()

End Sub
Sub Ascending()
    Dim A, B, C, D, E, F As Integer

End Sub
Sub Decending()
    Dim A, B, C, D, E, F As Integer

End Sub
End Module

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

首先,您最好将数字输入数组。然后你可以使用Array.Sort方法按升序排序,然后使用它和Array.Reverse方法对数组进行排序并尊重它。

Dim Numbers() as String

Numbers(0) = Console.ReadLine()
Numbers(1) = Console.ReadLine()
Numbers(2) = Console.ReadLine()
Numbers(3) = Console.ReadLine()
Numbers(4) = Console.ReadLine()
Numbers(5) = Console.ReadLine()
Numbers(6) = Console.ReadLine()

Dim Up As System.Threading.Thread = New Threading.Thread(AddressOf Ascending)

    'Setting Up as a thread

    Up.Start()

    Dim Down As System.Threading.Thread = New Threading.Thread(AddressOf Decending)

    Down.Start()

    Console.ReadKey()

Sub Ascending()
    Array.Sort(Numbers)
End Sub

Sub Decending()
    Array.Sort(Numbers)
    Array.Reverse(Numbers)
End Sub