0% found this document useful (0 votes)
197 views5 pages

CSCI250 - Sample Final Exam

Introduction to Programming Sample Final Exam

Uploaded by

52230159
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
197 views5 pages

CSCI250 - Sample Final Exam

Introduction to Programming Sample Final Exam

Uploaded by

52230159
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CSCI250 Sample Final Exam

Lebanese International University - All Campuses


School of Arts and Sciences - Department of Computer Science
Course Name : Introduction to Programming Course Code : CSCI250
Date : Section :
Instructor : Rizkallah Bachour Time :

Number of pages : Allowed Time : 120 minutes

Problem# Grade Total Grade


Part 1
Problem 1 /25

Part 2 /100
Problem 1 /25
Problem 2 /25
Problem 3 /25

Good Luck

• Read each question carefully before answering.


• Cheating in any form will be punished with a ZERO grade.

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

3. int [] x = new int[6]; a. System.out.println(x);


To print all array elements we use: b. for (int i = 0; i < x.length - 1; i++)
System.out.println(x);
c. for (int i = 1; i < x.lengh; i++)
System.out.println(x[i]);
d. for (int i = 0; i < x.length; i++)
System.out.println(x[i]);
e. None of the above
4. Which of the statements is equivalent to
the below? a. int[] myArr = {0, 1, 2, 3};
b. int[] myArr = {1, 2, 3, 4};
int myArr [ ]= new int[4]; c. int[] myArr = {i+1, i+1, i+1, i+1};
for (int i = 0; i < myArr.length; i++) d. None of the above
myArr[i] = i + 1;

5. Which of the following loops is infinite? a. while (true)


b. for(int i = 0; ; i++)
c. Both a. & b.
d. None of the above

Page 2 of 5
CSCI250 Final Exam – v2 Spring 2020-2021

PART 2

Problem #1: [25 pts] Arrays


Write a program to help your instructor calculate the highest and the lowest grade in the final exam of
his/her CSCI250 section. Your program should ask the instructor to enter the number of students and then
the grade for every student. The grades should be stored in an array.
Then the program should find and display the highest and the lowest grade in the array as shown the sample
run below.

Sample run 1:

Enter the number of Students: 5


Enter grade for student 1: 80.5
Enter grade for student 2: 35
Enter grade for student 3: 75.5
Enter grade for student 4: 90
Enter grade for student 5: 63.4
The highest grade is 90
The lowest grade is 35.0

Sample run 2:

Enter the number of Students: 3


Enter grade for student 1: 80
Enter grade for student 2: 60
Enter grade for student 3: 80
The highest grade is 80
The lowest grade is 60

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

Use the following method header:

public static int[ ] checkArrays(int[ ] A, int[ ] B)

• [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:

public static void printArray(int[ ] arr)

• [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

You might also like