1.
It is a collection of values with the same data type.
Correct Answer
B. Array
Explanation
An array is a collection of values with the same data type. It allows us to store multiple values of the same type in a single variable, making it easier to manage and access the data. Arrays are commonly used in programming to store and manipulate large sets of data efficiently.
2.
The number of elements an array can hold depends on
Correct Answer
D. Size of an Array
Explanation
The number of elements an array can hold depends on the size of the array. The size of an array determines the amount of memory allocated for storing its elements. The size is specified when the array is declared and cannot be changed during runtime. Therefore, the size of an array directly affects the number of elements it can hold. The other options listed (type of array, index of array, and strength of array) do not determine the number of elements an array can hold.
3.
How are arrays identified
Correct Answer
C. By their array names
Explanation
Arrays are identified by their array names because the name of an array serves as a reference to the memory location where the array is stored. By using the array name, we can access and manipulate the elements of the array. The array name acts as a pointer to the first element of the array, allowing us to perform operations on the entire array using the name. Therefore, the array name is crucial in identifying and working with arrays in programming.
4.
This tells what kind of values an array can hold
Correct Answer
D. Type of an array
Explanation
The correct answer is "Type of an array" because the type of an array determines the kind of values it can hold. The type of an array specifies the data type of its elements, such as integers, strings, or objects. This is important because it determines the operations that can be performed on the array and the memory allocation required for each element.
5.
What type of values can the array String[] places = new String[20] hold?
Correct Answer
D. String
Explanation
The array "places" is declared as a String array with a size of 20. This means that each element in the array can hold a value of type String. Therefore, the array can hold String values and not integers, characters, or floating point numbers.
6.
In the array String[] places = new String[20], how many values can be stored in it?
Correct Answer
B. 20
Explanation
The given code creates an array of type String with a size of 20. The size of an array determines the number of elements it can store. In this case, since the size is 20, the array can store 20 values. Therefore, the correct answer is 20.
7.
The first index of an array should be always be ________?
Explanation
The first index of an array should always be 0. This is because in most programming languages, arrays are zero-indexed, meaning that the first element is accessed using the index 0. Therefore, the correct answer is 0.
8.
The highest possible index of an array should always be?
Correct Answer
C. . the size of the array -2
Explanation
The highest possible index of an array should always be the size of the array minus 1. This is because arrays are zero-indexed, meaning that the first element of the array is at index 0. Therefore, the last element of the array will be at index size of the array minus 1. For example, if an array has a size of 5, the highest possible index would be 4.
9.
It is used to access a value in array. In other words, it serves as the address of value in an array
Correct Answer
B. Array index
Explanation
The array index is used to access a specific value within an array. It represents the position or address of the value within the array. By using the array index, we can retrieve or modify the value at that particular location in the array. It is an essential concept in array manipulation and allows us to efficiently work with the elements stored in an array.
10.
Which of the following is the proper way of assigning values in an array?
Correct Answer
D. Int[] ages = {1.9, 2.9, 3.4, 3.5};;
Explanation
The correct way of assigning values in an array is by using the syntax "int[] ages = {1.9, 2.9, 3.4, 3.5}". This creates an array named "ages" of type int[], and assigns the values 1.9, 2.9, 3.4, and 3.5 to the elements of the array. The other options are incorrect: "int ages[1,2,3,4,5]" uses incorrect syntax for assigning values in an array, "int ages = {1,2,3,4,5}" is incorrect because the variable "ages" is declared as an int and not an array, and "int[5] ages = new int[{1,2,3,4,5}]" also uses incorrect syntax for assigning values in an array.
11.
It is a kind of array which contains another array(s). In other words, it is an array of arrays.
Correct Answer
D. Multidimensional
Explanation
A multidimensional array is a type of array that contains other arrays within it. It is often used to store data in a tabular format, such as a matrix or a grid. Unlike a one-dimensional array, which has a single row or column, a multidimensional array can have multiple dimensions, allowing for more complex data structures. This type of array is useful when dealing with data that has multiple dimensions or when organizing data in a hierarchical manner.
12.
It is form of array which can be represented in a tabular format - it has a row and a column
Correct Answer
B. Two-dimensional
Explanation
A two-dimensional array is a form of array that can be represented in a tabular format with rows and columns. Unlike a one-dimensional array, which only has a single row or column, a two-dimensional array allows for multiple rows and columns. This makes it suitable for representing data that has a two-dimensional structure, such as a grid or a matrix. In a two-dimensional array, elements are accessed using two indices, one for the row and one for the column.
13.
In the array int[][] temp = new int[5][7] how many rows can the array hold?
Correct Answer
B. 5
Explanation
The given array, int[][] temp = new int[5][7], can hold 5 rows. This is because the first dimension of the array declaration specifies the number of rows, which is 5 in this case. The second dimension specifies the number of columns, which is 7. Therefore, the array can hold 5 rows and 7 columns.
14.
In the array int[][] temp = new int[5][7] how many columns can the array hold?
Correct Answer
D. 7
Explanation
The given array declaration `int[][] temp = new int[5][7]` creates a 2-dimensional array with 5 rows and 7 columns. Therefore, the array can hold a maximum of 7 columns.
15.
It is an access modifier that lets the method be seen by other classes and methods
Correct Answer
A. Public
Explanation
Public is an access modifier that allows the method to be visible and accessible by other classes and methods. This means that any class or method in the program can call and use the public method. It is the most permissive access modifier, providing the widest accessibility to the method.
16.
Say we have a method public double add (double x, double y), what is the correct way to call this method in the main Java method
Correct Answer
C. Add(x,y)
Explanation
The correct way to call the method "add" in the main Java method is by using the syntax "add(x, y)". This means that we are passing two arguments, x and y, to the add method.
17.
It is an access modifier that lets the method be seen by other classes and methods but with reservations
Correct Answer
D. Protected
Explanation
The access modifier "protected" allows the method to be visible to other classes and methods within the same package or subclass, but not to classes outside the package. It provides a level of accessibility between the public and private access modifiers, allowing limited visibility and control over the method's usage.
18.
It refers to the type of data returned or accepted by the method
Correct Answer
D. Return type
Explanation
The return type of a method refers to the type of data that the method will return or accept. It specifies the data type of the value that the method will produce as output. In other words, it indicates the type of value that the method will "return" to the caller. The return type is an essential part of the method's signature and is declared in the method prototype and definition. It helps in determining the type of value that can be assigned or used when calling the method.
19.
This is used to execute a method. When invoked, the method body will then be executed
Correct Answer
C. Method call
Explanation
A method call is used to execute a method. When a method call is invoked, the method body will be executed. In other words, it is the action of actually running the code within a method. This is done by using the method's name followed by parentheses, which may include any necessary arguments or parameters.
20.
Int[] foo= {10, 12, 13, 15, 18};int n, result=0;int main (){for ( n=0 ; n<5 ; ++n )result += foo[n];}}What is the output of this program
Correct Answer
145, 1 4 5, 145.
Explanation
The output of this program is 145. The program initializes an integer array called "foo" with the values 10, 12, 13, 15, and 18. It then declares two integers, "n" and "result", with "result" initially set to 0. In the main function, a for loop is used to iterate through the elements of the "foo" array. On each iteration, the value of the current element is added to the "result" variable. After the loop completes, the final value of "result" is 145.
21.
Public class TestArray {
public static void main(String[] args) { double[] myList = {1.9, 2.9, 3.4, 3.5};
// Print all the array elements for (int i = 0; i < myList.length; i++) { System.out.println(myList[i] + " "); } // Summing all elements double total = 0; for (int i = 0; i < myList.length; i++) { total += myList[i]; } System.out.println("Total is " + total); // Finding the largest element double max = myList[0]; for (int i = 1; i < myList.length; i++) { if (myList[i] > max) max = myList[i]; } System.out.println("Max is " + max); }}
What is the output of this source code?
Correct Answer
1.9
2.9
3.4
3.5
Total is 11.7
Max is 3.5
Explanation
The given source code creates an array called "myList" with the values 1.9, 2.9, 3.4, and 3.5. It then prints each element of the array using a for loop. After that, it calculates the sum of all the elements in the array and prints the total. Finally, it finds the largest element in the array and prints it as the maximum. Therefore, the output of the source code will be:
1.9
2.9
3.4
3.5
Total is 11.7
Max is 3.5
22.
Public static void main(String[] args){ Scanner console = new Scanner(System.in); int n, temp=0; S.O.P("Enter a positive integer: "); n=console.nextInt(); temp = mysteryFunction (n); if(temp==0) S.O.P( n + " is a prime number."); else S.O.P( n +" is not a prime number."); return 0;} public int mysteryFunction(int n){ int i, flag=0; for(i=2;i<=n/2;++i) { if(n%i==0) { flag=1; break; } } return flag;}
What will be the output if the user inputs the value of the ffg as the value of n?
1.) n = 5 2.) n=-2 3.) n = 250 4.) n=05.) n = 10
Correct Answer
5 is a prime number Error 250 is not a prime number 0 is not a prime number 10 is not prime number
Explanation
The correct answer is 5 is a prime number. The mysteryFunction is checking if the input number is divisible by any number from 2 to n/2. If it is divisible by any number, the flag variable is set to 1, indicating that the number is not a prime. If the flag variable remains 0, it means that the number is not divisible by any number and hence it is a prime number. In this case, the input number is 5, which is not divisible by any number from 2 to 5/2 (which is 2), so the flag remains 0 and the output is "5 is a prime number".
23.
Type question here. Example: Practice makes you ________
Correct Answer
N/A