举一反三
- 使用数组x输出10个1-100之间的随机整数(包括1和100),下列命令中正确的是:( ) A: Dim x(9) As Integer For i = 1 To UBound(x) x(i) = Int(Rnd() * 100 + 1) Print x(i); Next B: Dim x(9) As Integer For i = 0 To UBound(x) x(i) = Rnd(10) Print x(i); Next C: Dim x(9) As Integer For i = 0 To UBound(x) x(i) = Int(Rnd() * 100 ) Print x(i); Next D: Dim x(9) As Integer For i = 0 To UBound(x) x(i) = Int(Rnd() * 100 + 1) Print x(i); Next
- 若要定义一个10个元素的整数数组,每个元素的值均为5,则下列语句正确的是___________。 A: Dim a%(9) = 5 B: Dim a%(10) = 5 C: Dim a%(9) = (5) D: Dim a%(9), i% For i = 0 To 9 a(i) = 5 Next
- 执行以下程序,MsgBox输出的值是________。Dim i, a(9) As Integera(0) = 1a(1) = 1For i = 2 To UBound(a)a(i) = a(i - 1) + a(i - 2)Next iMsgBox(a(9))
- 执行以下程序段后,数组b中的元素个数有________个。Dim a() As Integer = {2, 15, 9, 4, 5, 56, 74, 8, 43, 10}Dim b(9) As IntegerDim count As Integer = 0Dim i As IntegerFor i = 0 To UBound(a)If a(i) Mod 2 = 0 Thenb(count) = a(i)count += 1End IfNextReDim Preserve b(count - 1)
- 使用下列命令定义了数组x后,所有数组元素具有相同的 ( )Dim x(99) As IntegerFor i = 0 To UBound(x) x(i) = iNext i A: 存储地址 B: 下标 C: 值 D: 类型
内容
- 0
要将字符串数组a中所有学生姓名按数组下标顺序追加到列表框List1中,可以使用的程序段为( )。 A: List1.AddItem a B: For i = 0 To UBound(a) - 1 List1.AddItem a(i), 0 Next i C: For i = 0 To UBound(a) – 1List1.List(i)=a(i)Next i D: For i = 0 To UBound(a) - 1 List1.AddItem a(i) Next i
- 1
若有数组Dim a%(10)且每个元素有值,统计前一个元素大于后一个元素的次数,结果存放在变量n中。则下列语句正确的是___________。 A: Dim i%, n% For i = 1 To 10 If a(i) > a(i + 1) Then n = n + 1 End If Next MsgBox(n) B: Dim i%, n% For i = 1 To 10 If a(i) > a(i + 1) Then n = a(i) End If Next MsgBox(n) C: Dim i%, n% For i = 0 To 9 If a(i) > a(i + 1) Then a(i) = n + 1 End If Next MsgBox(n) D: Dim i%, n% For i = 0 To 9 If a(i) > a(i + 1) Then n = n +1 End If Next MsgBox(n)
- 2
以下程序输出的结果是: Private Sub Form_Activate() Dim a a=Array(1,2,3,4,5) For i=Lbound(((A) To Ubound(((A) A(i)=i*a(i) Next i Print i, Lbound(((A) , Ubound(((A) , a(i) End Sub
- 3
设有数组定义:int a[ ] = { 11 , 22 , 33 , 44 , 55 , 66 , 77 , 88 , 99 }; 则执行以下几个语句后的输出结果是 ______ 、 ______ 、 ______ 。 for ( int i = 0 ; i < a.length ; i ++ ) if ( a[i]%3==0 ) System.out.println(a[i]);[/i][/i]
- 4
智慧职教: 设有数据定义语句int i=3,x[4]={1,2,3};,则数组元素x[i]的值是。[/i]