Public Class Form1
Dim Names(10) As String
Dim Scores(10) As Integer
'查询,返回-1表示未找到该学生
Public Function GetScoreByName(ByVal name As String) As Integer
For i As Integer = 0 To 9
If name = Names(i) Then
Return Scores(i)
End If
Next
Return -1
End Function
'排序,输出名字和分数,格式:"1.张三:80"
Public Function GetNamesSortByScore() As String
For i As Integer = 0 To 9
For j As Integer = i + 1 To 9
If Scores(i) < Scores(j) Then
Dim temp1 As Integer = Scores(i)
Dim temp2 As String = Names(i)
Scores(i) = Scores(j)
Names(i) = Names(j)
Scores(j) = temp1
Names(j) = temp2
End If
Next
Next
Dim returnstring As String = ""
For index As Integer = 0 To 9
returnstring = returnstring & (index + 1).ToString() & "." & Names(index) & ":" & Scores(i).tostring() & vbCrLf
Next
Return returnstring
End Function
End Class
温馨提示:答案为网友推荐,仅供参考