CSBP221
CSBP221
Spring 23
Lab 4
SET: 1
Exercise#1: Define a method called calacFactorial that acepts one argument as an integer to
calculate and return the factorial of a given number N by user input.
Exercise #2: Write a Java program that declares an array numbers of 50 integer elements.
a. Initialize the array so that the first 25 elements are equal to the square of the
index variable and the last 25 elements are equal to three times the index variable.
b. Print out the array values, so that each 10 elements per line are printed.
c. Redo part a, but the first 25 elements are randomly generated between
and 10 and 50 and the last 25 elements are randomly generated between -25
and 25.
d. Count and display how many elements are positive and how many are negative.
e. Find and print the maximum value and the minimum value in the array.
SET: 2
Exercise #1:
a. Declare two arrays called arrayA and arrayB that holds integers, and the size
of the two arrays N is given by the user.
b. The main method calls a method called fillArray(…) of type void to fill an array
with a set of random generated integers between 7 and 33. This method
should be called twice to fill arrayA and then arrayB.
c. The main method calls another method called printArray (…) of type void to
display the elements of the array 5 elements per lines. This method should be
called twice to print arrayA and then arrayB.
d. The main method calls another method called count (…) of type integer to count
and return the total number of integers greater than a value enter by the user
(passed to the function).
e. Then the main methods calls another method called isSame( … ) of type boolean
to check if the two arrays arrayA and arrayB have the same elements or not.
f. The main method calls a method called findAverage(…) of type double that
calculates and returns average of all the values in arrayA or arrayB.
Then, main method calls a method called aboveAverage(…) of type integer that
finds and returns how many numbers in arrayA are above the average
2/2