# CSCI 1133 Midterm, part 1 PAC I solution

\$29.99

Original Work ?

## Description

1) Short answers (10 points) :
a. (2 points) Given the following array declaration:
int [] array = new int[8]; What are the valid subscripts?
b. (2 points) What two pieces of information can you get from a method header besides the
name of the method?
c. (2 points) BRIEFLY describe the difference between pass by value and pass by reference.
d. (4 points) BRIEFLY explain what it means to “overload” a method and provide a simple
2. (20 points) Write a method that takes a sorted int array as a parameter and returns a count of
the number of duplicates in the array.
The following are just examples. Your implementation must be able to handle arrays of
different sizes with different numbers, but you can always assume that the arrays will be sorted.
Note that you do not need to write a class or main method; just the method as described above.
Example:
int[] arr = {1,1,1,2,2,5,8,12,12,14,14,15}
int dupes = countDuplicates(arr);
// dupes = 5;
Example:
int[] arr = {1,5,23,42,101};
int dupes = countDuplicates(arr);
// dupes = 0;
3. (20 points) Write a Java method with the name printBox. printBox has 3 parameters: the first
is an integer which determines how many rows should be printed, the second is an integer
which determines how many columns should be printed and the third is the character to be
printed. printBox does not return a value to the calling method.
Write a main() that prompts the user for the three values needed to call this method. Then main
should call the method with those values.
When called as follows:
printBox (3, 4, ‘a’);
printBox should display the following box (which has 3 rows and 4 columns) on the screen:
aaaa
aaaa
aaaa
When called as follows:
printBox (2, 8, ‘+’);
printBox should display the following box (which has 2 rows and 8 columns) on the screen:
++++++++
++++++++