250+ TOP MCQs on Sorting a One-Dimensional Array and Answers

Visual Basic Multiple Choice Questions on “Sorting a One-Dimensional Array”.

1. ________ method is used to sort an array in visual basic.
a) Array.arrange()
b) Array.arrayArrange()
c) Array.Sort()
d) Array.sortAscending()

Answer: c
Clarification: You can use the Array.Sort method to sort a one-dimensional array’s values in ascending order. To sort the values in descending order, you first use the Array.Sort method to sort the values in ascending order, and then use the Array.Reverse method to reverse the values. The syntax is as follows, where the arrayName is the name of the array:
Array.Sort(arrayName)

2. Arranging data in a specific order is called as ___________
a) Arranging
b) Sorting
c) Organizing
d) Making

Answer: b
Clarification: In some applications, you might need to arrange the contents of an array in either ascending or descending order. Arranging data in a specific order is called sorting. When an array is sorted in ascending order, the first element in the array contains the smallest value and the last element contains the largest value. When an array is sorted in descending order, on the other hand, the first element contains the largest value and the last element contains the smallest value.

3. __________________ method is used to reverse the values.
a) Array.Reverse
b) Array.Sort Desc
c) Array.Sort Asc
d) Array.rev

Answer: a
Clarification: You can use the Array.Sort method to sort a one-dimensional array’s values in ascending order. To sort the values in descending order, you first use the Array.Sort method to sort the values in ascending order, and then use the Array.Reverse method to reverse the values. The syntax is as follows, where the arrayName is the name of the array:
Array.Reverse(arrayName)

4. What will be the output of the following Visual Basic code?

Dim intScores As Integer = {78, 83, 75, 90}
Array.Sort(intScores)

a) 78, 83, 75,90
b) 75,78, 83,90
c) 78,75,83,90
d) 90,83,78,75

  250+ TOP MCQs on Dynamic Web Pages and Answers

Answer: b
Clarification: Array.Sort sorts the array in ascending order. In the question above it sorts the contents of the array in ascending order, as follows: 75, 78, 83, and 90.

5. What will be the output of the following Visual Basic code?

Dim intScores As Integer = {78, 83, 75, 90}
Array.Reverse(intScores)

a) 78, 83, 75,90
b) 75,78, 83,90
c) 78,75,83,90
d) 90,75,83,78

Answer: d
Clarification: Array.Reverse method reverses the array list. In the above question it reverses the contents of the array, placing the values in the following order: 90, 75, 83, and 78.

6. What will be the output of the following Visual Basic code?

Dim intScores As Integer = {78, 83, 75, 90}
Array.Sort(intScores)
Array.Reverse(intScores)

a) 78, 83, 75,90
b) 75,78, 83,90
c) 78,75,83,90
d) 90,83,78,75

Answer: d
Clarification: Array.Sort sorts the content of the array in ascending order, and then Array.Reverse reverses the array list, thus we get sorted array in descending order. In the above question, it sorts the contents of the array in ascending order and then reverses the contents, placing the values in descending order as follows: 90, 83, 78, and 75.

7. What is the array of these statements?

Dim intScores As Integer = {78, 83, 75, 90}
Array.reverse (intScores)

a) { 75, 78, 83, 90}
b) { 78, 75, 90, 83 }
c) { 90, 83, 78, 75 }
d) Compilation Error

Answer: d
Clarification: The command to reverse array list is Array.Reverse, and not array.reverse, thus it leads to compilation error. The syntax is as follows, where the arrayName is the name of the array:
Array.Reverse(arrayName)

8. What is the array of these statements?

Dim intScores As Integer = {78, 83, 75, 90}
Array.sort (intScores)

a) {75, 78, 83, 90}
b) {78, 75, 90, 83}
c) {90, 83, 78, 75}
d) Compilation Error

  250+ TOP MCQs on Using Pattern Matching to Compare Strings

Answer: d
Clarification: The command to sort array list is Array.Sort, and not Array.sort. Thus it leads to compilation error. The syntax is as follows, where the arrayName is the name of the array:
Array.Sort(arrayName)

9. Which of the following statements assigns (to the intElements variable) the number of elements contained in the intNums array?
a) intElements = Len(intNums)
b) intElements = Length(intNums)
c) intElements = intNums.Len
d) intElements = intNums.Length

Answer: d
Clarification: The number of elements in a one-dimensional array is stored, as an integer, in the array’s Length property.The syntax is as follows:
arrayName.Length

10. Which of the following assigns the string “Rover” to the fifth element in a one-dimensional array named strPetNames?
a) strPetNames(4) = “Rover”
b) strPetNames[4] = “Rover”
c) strPetNames(5) = “Rover”
d) strPetNames.Items.Add(5) = “Rover”

Answer: a
Clarification: An array is populated with the following syntax: arrayname(index)=”value”; where index is of between the range 0 to (length of array -1). Thus in this example, strPetnames(4)=”Rover”, is the proper initialization of the array.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top