VB 索引超出了数组界限
做一个反序排列的题。第一步生成十个二位数,这个没有问题。第二步,反序。我编了两种代码,但是都有问题。请教哪里有问题。代码一:Dimi,j,tAsIntegerFori=0...
做一个反序排列的题。
第一步生成十个二位数,这个没有问题。
第二步,反序。
我编了两种代码,但是都有问题。
请教哪里有问题。
代码一: Dim i, j, t As Integer
For i = 0 To 9
j = 9 - t
If i < j Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next
TextBox2.Text = ""
For i = 0 To 9
TextBox2.Text = TextBox2.Text + CStr(a(i)) + " "
Next
代码二:
dim j as integer
textbox2.text=" "
for j = 9 to 0 step -1
textbox2.text=textbox2.text+cstr(a(j))+" "
next
end sub 展开
第一步生成十个二位数,这个没有问题。
第二步,反序。
我编了两种代码,但是都有问题。
请教哪里有问题。
代码一: Dim i, j, t As Integer
For i = 0 To 9
j = 9 - t
If i < j Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next
TextBox2.Text = ""
For i = 0 To 9
TextBox2.Text = TextBox2.Text + CStr(a(i)) + " "
Next
代码二:
dim j as integer
textbox2.text=" "
for j = 9 to 0 step -1
textbox2.text=textbox2.text+cstr(a(j))+" "
next
end sub 展开
1个回答
展开全部
'生成两位数
Dim a(9) As Integer
For k = 0 To 9
a(k) = Int(90 * Rnd + 10)
Print a(k)
Next k
'反序,输出至text2
Dim i, j, t As Integer
For i = 0 To 9
For j = i + 1 To 9
If a(i) < a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next j
Next i
Text2 = ""
For i = 0 To 9
Text2 = Text2 + CStr(a(i)) + " "
Next i
Dim a(9) As Integer
For k = 0 To 9
a(k) = Int(90 * Rnd + 10)
Print a(k)
Next k
'反序,输出至text2
Dim i, j, t As Integer
For i = 0 To 9
For j = i + 1 To 9
If a(i) < a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next j
Next i
Text2 = ""
For i = 0 To 9
Text2 = Text2 + CStr(a(i)) + " "
Next i
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询