Professional Documents
Culture Documents
(Write your name on THIS PAGE ONLY!!!) (Write your ID# on this and every page!!!)
Instructions:
3. Write your STUDENT ID Number on every page. If you do not write your ID Number on a
certain page, you will not receive credit for the question on that page!
4. Do not write your name on any page (except this one). If you write your name on a certain page,
you will not receive credit for the question on that page!
5. There are five problems on the exam, one per page. Each problem will be graded as "pass" or "fail".
To pass this final exam, you must pass at least three out of the five questions. Once you start, verify
you have all 5 problems.
6. You must give your answer to a question on the same sheet of paper that the problem appears
on. If you run out of space on the front of the page, you may continue to the back of that page
only. If you put your answer on a different page, you will not receive credit for that problem!
7. For problems that ask you to write a method, you must use the given method header exactly as
shown, and you do not need to write the main( ) method.
8. For problems that ask you to write code, you should only write the method indicated in the
problem. You can assume the following import statement and keyboard declarations:
import java.util.Scanner;
9. You may use "SOP" as an abbreviation for "System.out.print" and "SOPln" for
"System.out.println".
10. You do not need to do any error checking of input values, unless the problem specifically asks
you to do so!
11. If you are caught looking at other papers or communicating with other students in any way, you will
receive an F for the course.
WRITE your STUDENT ID# here: ____________________________
Problem 1 Write the method public static int rangeProduct(int a, int b).
Assume that 𝑎 < 𝑏. Your method must compute and return the product of the integers in the range
from 𝑎 to 𝑏. For example, if 𝑎 = 3 and 𝑏 = 6, your method would compute and return the product
3 × 4 × 5 × 6 = 360.
Problem 2 Write a program that has the user enter three integers a, b, and c. The user may enter the same value
more than once. Print to the console the number of times the largest integer among a, b, and c was entered.
Here are some sample runs:
The largest integer 48 The largest integer 923 The largest integer 50
was entered once. was entered twice. was entered three times.
}
CS-200, Common Final Exam, Spring, 2016, Page 3 of 6.
WRITE your STUDENT ID# here: ____________________________
Problem 3 Write the method: public static String doubleVowels(String x). This method
takes a String x and returns a new String y which is identical to x except wherever there is a vowel in x, there will
be two of that same vowel in the returned String y. The original String x will contain only lower case letters.
Problem 4 Write a program that has the user enter enter integers between 0 and 9999 until the user enters some
integer twice. Your program then prints to the console window how many distinct integers were entered. You
may assume all integers entered by the user are between 0 and 9999. Here are some sample runs:
}
CS-200, Common Final Exam, Spring, 2016, Page 5 of 6.
WRITE your STUDENT ID# here: ____________________________
Problem 5 Write the method: public static int largestInCommon(int [] A, int [] B).
This method takes two arrays A and B, each containing positive integers only (no error checking necessary)
and returns the largest value that is common to both A and B. If there is no value that is contained in both
A and B, return the value –1. Here are some examples:
If A = {3, 8, 5, 2, 7, 9} and B = {5, 1, 22, 7, 2, 15, 3}, the return value would be 7.
If A = {35, 12, 19, 35, 45} and B = {55, 99, 12}, the return value would be 12.
If A = {33, 11, 77, 44, 55} and B = {99, 88, 222, 66, 1000}, the return value would be –1
}
CS-200, Common Final Exam, Spring, 2016, Page 6 of 6.