CSCI250 - Sample Final Exam
CSCI250 - Sample Final Exam
Part 2 /100
Problem 1 /25
Problem 2 /25
Problem 3 /25
Good Luck
Page 1 of 5
CSCI250 Sample Final Exam
PART 1
Problem #1: [25 pts: 5 pts for each] Answer the following questions
Answer
1. Which of the statement on the right is
correct about the below code when the body a. n, z, and x have the same value.
of the method is executed? b. Only n and x have the same value.
c. Only n and z have the same value.
public class TEST { d. None of the above
public static void main(String[] args) {
int n = 25;
method(n);
}
public static void method(int x) {
x++;
int z = x;
z = z – 4;
}
}
2. To get the size of an array called
“myArray” we use: a. myArray.length();
b. myArray.size;
c. myArray.length;
d. Size(myArray);
e. None of the above
Page 2 of 5
CSCI250 Final Exam – v2 Spring 2020-2021
PART 2
Sample run 1:
Sample run 2:
Page 3 of 5
CSCI250 Final Exam – v2 Spring 2020-2021
PART 2
Problem #2: [25 pts] Methods
a) Write a boolean method called productDivisibleByThree that returns true if the product of the digits of
its integer parameter is divisible by 3 and false otherwise. For example, if the value passed to the method
is 23 then the product of its digits is 6 (2*3). The method should return true since 6 is divisible by 3.
b) Write a main method that calls the method productDivisibleByThree for the values between 10 and 50
inclusive 10 per line. This should output the following numbers:
10 13 16 19 20 23 26 29 30 31
32 33 34 35 36 37 38 39 40 43
46 49 50
Answer:
Page 4 of 5
CSCI250 Final Exam – v2 Spring 2020-2021
PART 2
Problem #3: [25 pts] Arrays and Methods
• [10 pts] Write a method called checkArrays that accepts as parameters two arrays of integer (A and
B of the same size) and returns another array of integers (C) initialized as follows: C[i] = 1 if B[i]
divides A[i], otherwise C[i] = 0. For example:
A 12 20 4 30 17
B 3 6 24 15 9
C 1 0 0 1 0
• [5 pts] Write a void method called printArray that accepts as parameters an array of integers and
print its values. Use the following method header:
• [10 pts] Write a main method to test the above methods as follows:
- Declare and initialize 2 integer arrays (arrayA and arrayB) of size 5 (fill the 2 arrays with random
integers between 1 and 100).
- Invoke the method printArray to display the values stored in the two arrays.
- Invoke the method checkArrays and pass to it the two arrays arrayA and arrayB.
- Invoke the method printArray to display the values of the new array (arrayC).
Sample Run:
ArrayA: 12 20 4 30 17
ArrayB: 3 6 24 15 9
ArrayC: 1 0 0 1 0
Page 5 of 5