Sample Midterm Csc 201

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Sample Midterm Csc 201 as PDF for free.

More details

  • Words: 331
  • Pages: 3
CSC 201 SAMPLE MIDTERM QUESTIONS Instructions: 1) This is a closed book, closed notes exam. Do not use notes, computers, and calculators in completing this exam. 2) Answer the test on this sheet. Please use extra paper for rough work. 3) Remember to read the questions to its entirety. 4) You have 1 hour and 45 minutes to complete this exam (11:00am– 12:45pm).

Problem 1- 20 points For the given problem below determine how many times the body of the loop is executed. a)

for(int x=1 ; x < 10; x++) { System.out.println(x); }

b)

What is the output of the following code? System.out.println(“B”+4+5);

c)

What is the output for the foll. Code? for(int I = 3 ; i<= 7 ; i+=2) { System.out.println(i); i = i-1; }

Problem 2: (20 points) In this problem, we have a class triangle which is defined. Write a method called getType() which says whether a triangle is isosceles, or scalene or equilateral. Your method should return a ‘String’ saying what kind of a triangle it is.

Public class triangle{ Public static void main(String[] args) { int side1, side2, side3;

} }

Problem 3:

20 points

Please answer the following questions in the space provided. 1) Give an example of ‘if loop’ construct.

2) What is a ternary operator in Java? Give one example.

3) What is indexing in an array?

Problem 4: 20 points Write a program to calculate the sum of the array elements assuming that the array is an integer array.

Problem 5: 20 points Write a method called ‘sort()’ to sort the elements of an array of floats and call that method from your main method. Any sorting technique can be used to perform the sorting operation.(Hint: Bubble Sort algorithm).

Problem 6: 10 points Write a Java method to accept two input strings from the user and concatenate the two strings. Your method should return a String which is concatenation of user inputs.

Problem 7:

Extra credit question may be given.

Related Documents

Csc 201-lecture 8
June 2020 1
Csc 201-homework1
June 2020 6
Csc 201-lecture 7
June 2020 1
Csc 201-homework3
June 2020 0