冒泡排序是经典的循环结构处理案例,下面是一个冒泡排程序:
请补充下划线的内容j :
Dim I, J, AA(9) As Short
Dim Temp As Short
For I = 0 To 9
AA(I) = InputBox("请输入第" & I & "数", "输入窗口")
Next
For I = 1 To 8
For J = I + 1 To 9
If AA(I) > AA(J) Then
Temp = AA(I)
_______ '交换1
AA(J) = Temp
End If
Next
Next
....
请补充下划线的内容j :
Dim I, J, AA(9) As Short
Dim Temp As Short
For I = 0 To 9
AA(I) = InputBox("请输入第" & I & "数", "输入窗口")
Next
For I = 1 To 8
For J = I + 1 To 9
If AA(I) > AA(J) Then
Temp = AA(I)
_______ '交换1
AA(J) = Temp
End If
Next
Next
....
举一反三
- 下列程序段的执行结果为 _______。 Dim a(3, 5) As Integer Dim i As Integer, j As Integer For i = 1 To 3 For j = 1 To 5 a(i, j) = a(i - 1, j - 1) + (i - 1) * 5 + j Next j Next i Print a(3, 4)
- 下列程序: Option Base 1 Private Sub Form_Click() Dim a(5,5) For i = 1 To 5 For j = 1 To 5 k = k + 1 a (i,j)= k Next j Next i For i = 1 To 5 s = s + a (i,i) Next i Print s End Sub 运行时的输出结果是( )。
- 有如下语句,执行后该段语句的循环次数是_____。 Dim s,I,j as integer For I =1 to 3 For j=3 To 1 Step-1 S=I*j Next j Next I
- 下列程序段不能正确显示1!、2!、3!、4!的结果的是 。 A: For i = 1 To 4 For j = 1 To i n = 1 n = n * j Next j MsgBox( n)Next i B: Dim i%, j%, n%For i = 1 To 4 n = 1 For j = 1 To i n = n * j Next j MsgBox( n)Next i C: Dim j%, n%n = 1For j = 1 To 4 n = n * j MsgBox( n)Next j D: Dim j%, n%n = 1j = 1Do While j<=4 n=n*j MsgBox(n) j=j+1Loop E: Dim j%, n%n = 1j = 1Do n=n*j MsgBox(n) j=j+1Loop While j<=4
- 下面代码是实现数组array冒泡排序的片段,划线处应填入( ) int[] array = 60, 56, 38, 45 int temp for (int i = 0 i < 3 i++) for (int j = 0 j < __________ j++) if (array[j] < array[j + 1]) temp = array[j] array[j] = array[j + 1] array[j + 1] = temp