CSCI250 Introduction To Programming - FinalExam-Sample2 - Solution
CSCI250 Introduction To Programming - FinalExam-Sample2 - Solution
int b = 0; b) 7
{7, 3, 5}, d) 44
{1, 6, 9}};
for(int i = 0; i < a.length - 1; i++)
b += a[i+1][i];
System.out.println(b);
Page 1 of 5
CSCI250 Final Exam – v1 – solution Fall 2017 – 2018
MCQ 4 What is the output of the following
a) 5
code? b) 3
int[][] m = new int[3][5]; c) runtime Error
System.out.println(m[3].length); d) 15
MCQ 5
A method called T accepts 3 a) public static double average(double t1,
double parameters and double t2, double t3)
prints on the screen the b) public static void T(double t1, double
average of these numbers. t2, double t3)
What will the signature of c) public static double T(double a, double
this method be: b, double c)
MCQ 6
What is the correct syntax to create an array of a) int[] A = new
type int and initialized to 1, 2 and 3 int[1,2,3];
b) int [] A=new{
1,2,3};
c) int[] A;
A = { 1,2,3};
d) int[] A = {1,2,3};
MCQ 7
What does this method do? a) Counts and returns the number
of elements in array a
public static int count (int[] a){
int c=0; b) Counts and returns the number
for(int i=0;i<a.length;i++) of even numbers in array a.
if(a[i]%2==0)
c++; c) Counts and returns the sum of
return c; all even numbers in a.
}
Page 2 of 5
CSCI250 Final Exam – v1 – solution Fall 2017 – 2018
Question 2 [24 pts]:
package checksorting;
if (isSorted(numbers)) // 4pts
System.out.print("\n_BThis array is sorted.\n"); // 1pt
else
System.out.print("\nThis array is not sorted.\n"); // 1pt
}//end main
Page 3 of 5
CSCI250 Final Exam – v1 – solution Fall 2017 – 2018
Question 3 [30 pts]:
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int s; // 1pt
Page 4 of 5
CSCI250 Final Exam – v1 – solution Fall 2017 – 2018
Question 4 [25 pts]:
import java.util.Scanner;
while (n != 0) { // 2pts
int digit = n % 10; // 1pts
sum += factorial(digit); // 4pts
n=n/10; // 1pts
}
if(sum==m) // 2pts
System.out.println(m+" is a Strong number"); // 1pts
else
System.out.println(m+" is not a Strong number"); // 1pts
Page 5 of 5