100% found this document useful (1 vote)
82 views6 pages

Batangas State University: The National Engineering University

The document is a test for a Computer Science course on Object Oriented Programming. It contains a multiple choice test with questions about arrays and functions in Java. Specifically, it tests knowledge of one-dimensional and multi-dimensional arrays, including declaring and initializing arrays, accessing elements, and using arrays in code blocks. It also provides context that it is from the Integrated School of Batangas State University in the Philippines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
82 views6 pages

Batangas State University: The National Engineering University

The document is a test for a Computer Science course on Object Oriented Programming. It contains a multiple choice test with questions about arrays and functions in Java. Specifically, it tests knowledge of one-dimensional and multi-dimensional arrays, including declaring and initializing arrays, accessing elements, and using arrays in code blocks. It also provides context that it is from the Integrated School of Batangas State University in the Philippines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Republic of the Philippines

BATANGAS STATE UNIVERSITY


The National Engineering University
Pablo Borbon Campus
Rizal Avenue Ext., Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 980-0385; 980-0387; 980-0392 to 94; 425-7158 to 62 loc. 1136
E-mail Address: [email protected] | Website Address: http://www.batstate-u.edu.ph

Integrated School

DATA CHECK 6
Long Test (Array and Function)

Computer Science 10
Object Oriented Programming

Name: __________________________________ Date: _____________


Year Level and Section: ____________________

GENERAL DIRECTIONS:
1. Use permanent ink only in answering the tests. Erasures and alterations are not allowed.
2. Unanswered questions/items will be marked wrong.
3. Use the provided Answer Sheet.

I. Multiple Choice:
Directions: Choose letter the best answer in each of the following test items (1-40).

1. Which of the following best defines an array?


A. A type of data structure that can store multiple values of different kinds.
B. A type of data structure that can store a fixed-size sequential collection of elements of
the same kind.
C. A type of data structure that can store a fixed-size sequential collection of elements of
different kinds.
D. A type of data structure that can store multiple values of the same kind.

2. Arrays can be declared in Java by defining the variable type with:


A. curly braces
B. parentheses
C. square brackets
D. angle brackets

3. In programming, an index in an array is a value that:


A. identifies the data type of the array
B. specifies the size of the array
C. identifies the location of an element in the array
D. specifies the number of elements in the array

4. Which of the following is not a use of arrays?


A. Maintaining large data under a single variable name.
B. Sorting data elements easily.
C. Performing matrix operations.
D. Calculating trigonometric functions.

5. Which of the following is a valid way to declare and initialize an array?


A. int grades = [95, 86, 78, 91];
B. float[] numbers = 3.14, 2.71, 1.62;
C. double[] values = {2.5, 4.0, 6.7, 8.9};
D. char[] letters = "a", "b", "c", "d";

Leading Innovations, Transforming Lives, Building the Nation


6. What is the main advantage of using arrays instead of multiple variables?
A. It makes the program more complex
B. It helps to maintain large data under a single variable name
C. It makes it easier to store different types of data
D. It reduces the speed of the program

7. Why is it important to have a fixed size for arrays?


A. It makes the code simpler and easier to understand.
B. It reduces the amount of memory used in the program.
C. It allows for efficient storage and retrieval of data.
D. It allows for storing elements of different data types.

8. Which of the following describes a one-dimensional array?


A. An array that can store elements of different data types.
B. An array that can store a fixed-size sequential collection of elements of different kinds.
C. An array whose elements can be accessed individually by specifying the index value of
each element stored in the array.
D. An array that is used to perform complex mathematical operations.

9. A multi-dimensional array is an array:


A. that can store elements of different data types
B. that is used to perform complex mathematical operations
C. whose elements are also arrays
D. whose elements are fixed-size sequential collection of different kinds

10. Why is it important to learn about arrays in programming?


A. It makes the program more complex
B. It helps to achieve program objectives in a simpler and better way
C. It is not important to learn about arrays
D. It helps to reduce the size of the program

11. Which of the following is the correct syntax for declaring a single-dimensional array?
A. dataType arrayName;
B. dataType[arrayName];
C. arrayName[dataType];
D. dataType[] arrayName;

12. What is the maximum number of elements that can be stored in the following array: int[]
numArray = new int[7]?
A. 6
B. 7
C. 8
D. 9

13. What is the index of the first element in a one-dimensional array?


A. 0
B. 1
C. 2
D. -1

14. Which of the following is NOT true about one-dimensional arrays?


A. They can store only one type of data.
B. They are made up of one row or column of array members.
C. They can be initialized with a single statement.
D. They can have a maximum size of 100 elements.

Page 2 of 6
15. Which of the following is true about accessing elements in a one-dimensional array?
A. You can only access one element at a time.
B. You can access all elements in the array at once.
C. The first element in the array has an index of 1.
D. You can access elements in any order you want.

16. What is a 2D array also known as?


A. A table with rows and columns
B. A single row of data
C. A set of data in three dimensions
D. An array of arrays

17. How many indexes are needed to access data in a 2D array?


A. One index
B. Two indexes
C. Three indexes
D. Multiple indexes

18. What is the purpose of using a multidimensional array?


A. To arrange data in a single dimension
B. To arrange data in at least two dimensions
C. To arrange data in three dimensions
D. To arrange data in a random order

19. Which of the following is not a valid initialization of a two-dimensional array in Java?
A. int[][] num_array = {{1,2,3}, {4,5,6}};
B. int[][] num_array = {{1,2}, {3,4,5}};
C. int[][] num_array = {{1,2}, {3,4}, {5,6}, {7,8}};
D. int[][] num_array = {1,2,3,4,5};

20. What is the result of trying to access an element outside the bounds of a multidimensional
array in Java?
A. An ArrayIndexOutOfBoundsException is thrown
B. The element is set to null
C. The element is set to zero
D. The program terminates with an error message

For numbers 21-22, refer to the codes below:


int[][] arr = new int[numRows][numCols];
System.out.println("Enter elements:");
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
arr[i][j] = sc.nextInt();
}
}

21. Which of the following is the purpose of the given code?


A. It declares and initializes a two-dimensional integer array named "arr" with the
specified number of rows and columns, and prompts the user to enter elements for each
cell of the array.
B. It prints the elements of a two-dimensional integer array named "arr" to the console.
C. It creates a one-dimensional integer array named "arr" and prompts the user to enter
elements for each cell of the array.
D. It declares and initializes a two-dimensional integer array named "arr" with the
specified number of rows and columns, but does not prompt the user to enter any
elements.

Page 3 of 6
22. What is the data type of the variable "arr" in the given code block?
A. double
B. int
C. String
D. Boolean

For numbers 23-24, refer to the codes below:


int row = -1;
for (int i = 0; i < numRows; i++) {
int sum = 0;
for (int j = 0; j < numCols; j++) {
sum += arr[i][j];
}
if (sum % 2 == 0) {
row = i;
break;
}
}

23. What is the purpose of the given code?


A. It finds the sum of all elements in the 2D array.
B. It finds the row number of the row where the sum of all elements is even.
C. It finds the column number of the column where the sum of all elements is even.
D. It sorts the 2D array in ascending order based on the sum of elements in each row.

24. What is the value of "row" if the given 2D array has no row with an even sum of elements?
A. -1
B. 0
C. numRows - 1
D. undefined

For numbers 25-27, refer to the codes below:


public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the size of the array: ");
int size = input.nextInt();
int[] arr = new int[size];
for (int i = 0; i < size; i++) {
System.out.print("Enter element #" + (i+1) + ": ");
arr[i] = input.nextInt();
}
System.out.print(arr[0]);
for (int i = 1; i < size; i++) {
System.out.print(", " + arr[i]);
}
}

25. What is the purpose of the for loop in this program?


A. To print the elements of the array to the console.
B. To initialize the elements of the array.
C. To calculate the sum of the elements in the array.
D. To determine the size of the array.

26. What happens if the user enters a non-numeric value when prompted for the size of the
array?
A. The program terminates with an error.
B. The program prompts the user to enter a numeric value.
C. The program initializes the array with a default size.
D. The program continues to execute normally, but the array may not be initialized
properly.
Page 4 of 6
27. How are the elements of the array printed to the console?
A. By using the System.out.println() method.
B. By using the Arrays.toString() method.
C. By iterating over the elements of the array with a for loop.
D. By passing the array to the System.out.print() method.

28. What is a function in programming?


A. A container for a few lines of code that accomplish a specific task.
B. A group of variables used to store data.
C. A type of loop used for iteration.
D. A set of conditions used to make decisions in the program.

29. What is the main benefit of using functions in programming?


A. To write longer and more complex code.
B. To avoid DRY (Don't Repeat Yourself) code.
C. To make code more difficult to read and maintain.
D. To slow down the program's execution speed.

30. A predefined function in programming is:


A. defined by the user to perform specific tasks.
B. built into the language to perform operations.
C. used to store data in the program.
D. used to make decisions in the program.

31. What is the purpose of a return statement in a function?


A. To stop the execution of the program.
B. To skip a block of code in the function.
C. To return a value from the function to the calling code.
D. To print a message to the console.

32. How can functions help in tracking a large program?


A. By making the program run faster.
B. By reducing the number of variables used in the program.
C. By making the program more difficult to read and maintain.
D. By dividing the program into multiple functions that can be easily tracked.

33. What is the difference between a void function and a function with a return value?
A. A void function does not return anything, while a function with a return value does.
B. A void function is used to store data, while a function with a return value is used for
calculations.
C. A void function is faster than a function with a return value.
D. A void function can be called from any location in a program, while a function with a
return value cannot.

34. What is the difference between predefined functions and user-defined functions in Java?
A. Predefined functions are defined by the user, while user-defined functions are built into
the Java language.
B. Predefined functions are used for specific tasks, while user-defined functions are used
to perform operations.
C. Predefined functions are stored in the Standard Function Library, while user-defined
functions are not.
D. Predefined functions are already defined in the Java language, while user-defined
functions are defined by the programmer.

35. Which of the following is an example of a user-defined function in Java?


A. Math.sqrt()
B. System.out.println()
C. public static int sum(int a, int b) { return a + b; }
D. Scanner input = new Scanner(System.in);

Page 5 of 6
For numbers 36-40, refer to the codes below:
public static int compare(int a, int b, int c) {
if (a >= b && a >= c) {
return a;
} else if (b >= a && b >= c) {
return b;
} else {
return c;
}
}

public static void main(String[] args) {


Scanner scan = new Scanner(System.in);
int a, b, c;
System.out.print("Enter number 1: ");
a = scan.nextInt();
System.out.print("Enter number 2: ");
b = scan.nextInt();
System.out.print("Enter number 3: ");
c = scan.nextInt();
int greatest = compare(a, b, c);
System.out.println("Greatest: " + greatest);
}

36. What is the purpose of the compare method in the given code?
A. To compare the values of three numbers and return the greatest one.
B. To compare the values of three numbers and return the smallest one.
C. To calculate the average of three numbers and return the result.
D. To calculate the sum of three numbers and return the result.

37. What are the parameters of the compare method in this code?
A. a, b, c
B. scan
C. greatest
D. There are no parameters

38. What type of data does the compare method return?


A. boolean
B. int
C. String
D. Double

39. What happens if two or three of the input numbers are equal in value?
A. The compare method returns one of the equal numbers.
B. The compare method returns zero.
C. The compare method returns -1.
D. The compare method returns an error.

40. What happens if the user inputs a non-numeric value?


A. The program crashes and terminates.
B. The Scanner object prompts the user to input a number again.
C. The compare method returns -1.
D. The main method prints an error message and terminates.

Prepared:

Mr. LUIS PHILIP M. OROPESA


Teacher, Computer Science 10
Date Signed: February 24, 203

Page 6 of 6

You might also like