1 Short Answer (15 Points Each)

Size: px
Start display at page:

Download "1 Short Answer (15 Points Each)"

Transcription

1 COSC 7 Exam # Solutions Spring 08 Short Answer (5 Points Each). Write a method called RollCount that takes in two integer parameters rolls and target. The method should simulate the rolling of two die, rolls times, and count the number of rolls that result in the target value. The method should return that count. public static int RollCount(int rolls, int target) { int count = 0; 3 for (int i = 0; i < rolls; i++) { int die = (int) (Math.random() * 6) + ; 5 int die = (int) (Math.random() * 6) + ; 6 if (die + die == target) 7 count++; 8 } 9 return count; 0 }. Write a method called ExtractFirst that takes a single string as a parameter, extracts the first word from the string and returns that word. public static String ExtractFirst(String s) { int pos = s.indexof(" "); 3 String sub = s.substring(0, pos); return sub; 5 } 3. Write a method called InputIntRange that takes in two integer parameters min and max. The method should continually ask the user to input an integer value until the input value is between min and max (inclusively). Once the input is in the range the method should return that value. public static int InputIntRange(int min, int max) { Scanner kb = new Scanner(System.in); 3 int value = 0; do { 5 System.out.print("Input an integer: "); 6 value = kb.nextint(); 7 } while (value < min value > max); 8 return value;. Write a method called DoubleFactorial that takes a single integer parameter n and returns the double factorial of n. The double factorial of a number n is defined to be n!! = n (n ) (n ) We define 0!! = and if the value of n is less than 0 simply have the method return. For example,!! = = 8, 5!! = 5 3 = 5, 6!! = 6 = 8, and 0!! = = 380. public static int DoubleFactorial(int n) { if (n < 0) 3 return -; 5 int df = ; 6 for (int i = n; i > 0; i-=) 7 df *= i; 8 return df;

2 COSC 7 Exam # Solutions Spring 08 Program Traces (5 Points Each). For each of the given inputs, write the output of the program. import java.util.scanner; 3 public class ExamTrace { 5 public static int mth(int b, int c, int a) { 6 System.out.println(""); 7 System.out.println(a + " " + b + " " + c); 8 return a - b * c; 0 public static int mth(int a, int b, int c) { System.out.println("In Method "); 3 System.out.println(a + " " + b + " " + c); if (a > b) 5 return mth3(a, b, c); 6 else 7 return mth3(b, a, c); 8 } 9 0 public static int mth3(int c, int b, int a) { System.out.println(""); System.out.println(a + " " + b + " " + c); 3 return mth(a, b, c); } 5 6 public static int mth(int b, int a, int c) { 7 System.out.println("In Method "); 8 System.out.println(a + " " + b + " " + c); 9 if (a > b && b > c) 30 return a; 3 else if (a > b) 3 return c; 33 else 3 return mth(c, b, a); 35 } public static void main(string[] args) { 38 Scanner kb = new Scanner(System.in); 39 System.out.print("Input: "); 0 int a = kb.nextint(); int b = kb.nextint(); int c = kb.nextint(); 3 System.out.println(mth(a, b, c)); 5 System.out.println(); 6 System.out.println(mth(a, b, c)); 7 System.out.println(); 8 System.out.println(mth(a, b, c)); 50 } (a) Input: 3 3 In Method In Method 3 3 (b) Input: In Method In Method 3 In Method 3 3 3

3 COSC 7 Exam # Solutions Spring 08. For each of the given inputs, write the output of the program. import java.util.scanner; 3 public class ExamTrace { 5 public static String DoSomething(String str, String str, int p) { 6 str += " "; 7 int c = 0; 8 int pos = -; 9 while (c < p) { 0 pos = str.indexof(str, pos + ); if (pos >= 0) c++; 3 else return "Error"; 5 } 6 c = pos; 7 while (str.charat(c)!= ) { 8 c--; 0 c++; pos = str.indexof(" ", c); return str.substring(c, pos); 3 } 5 public static void main(string[] args) { 6 Scanner kb = new Scanner(System.in); 7 System.out.print("Input String: "); 8 String s = kb.nextline(); 9 System.out.print("Input String: "); 30 String s = kb.nextline(); 3 System.out.print("Input Number: "); 3 int a = kb.nextint(); 33 System.out.print(DoSomething(s, s, a)); 3 } 35 } (a) Input String: Methods are also known as functions and subroutines. Input String: o Input Number: functions Values of pos in the loop:, 5, 9, 3 Final value of c: 6 (b) Input String: Methods are also known as functions and subroutines. Input String: s Input Number: also Values of pos in the loop: 6, Final value of c: 3

4 COSC 7 Exam # Solutions Spring 08 3 Coding (0 Points) Do one and only one of the following exercises.. Write a program that will simulate rolling die repeatedly until you get a run of face values from up to a given number. That is, a run of would be rolling a, then 3, a run of 3 would be rolling a, 3, consecutively, a run of would be rolling, 3,, 5 consecutively, and so on. Have the program count the number of rolls needed for each possible run. The output should look like the following. Number of rolls needed for a run from to 3 = 353 Number of rolls needed for a run from to = 836 Number of rolls needed for a run from to 5 = 7587 Number of rolls needed for a run from to 6 = 755 Number of rolls needed for a run from to 7 = 5055 Number of rolls needed for a run from to 8 = 3705 Number of rolls needed for a run from to 9 = Number of rolls needed for a run from to 0 = Number of rolls needed for a run from to = Number of rolls needed for a run from to = public class ExamProgram { 3 public static void main(string[] args) { for (int run = 3; run <= ; run++) { 5 boolean done = false; 6 int target = ; 7 long count = 0; 8 while (!done) { 9 int die = (int) (Math.random() * 6) + ; 0 int die = (int) (Math.random() * 6) + ; int roll = die + die; 3 if (roll == target) target++; 5 else 6 target = ; 7 8 count++; 9 if (target == run + ) 0 done = true; } 3 System.out.println("Number of rolls needed for a run from to " + run + " = " + count); } 5 } 6 }

5 COSC 7 Exam # Solutions Spring 08. Write a program that will take an input string from the user and count the number of vowels in each word. The main program should take the input string and extract each word of the string, one by one. It should then call the a method that takes in a string, assumed to be a single word, counts the number of vowels and returns that number to the main. The main program should also print out the word and vowel count. The output should look like the following. Input String: Methods are also known as functions and subroutines Word: Methods Count = Word: are Count = Word: also Count = Word: known Count = Word: as Count = Word: functions Count = 3 Word: and Count = Word: subroutines Count = 5 import java.util.scanner; 3 public class ExamProgram { 5 public static int CountVowels(String s) { 6 int count = 0; 7 s = s.tolowercase(); 8 for (int i = 0; i < s.length(); i++) { 9 char ch = s.charat(i); 0 if (ch == a ch == e ch == i ch == o ch == u ) count++; } 3 return count; } 5 6 public static void main(string[] args) { 7 Scanner kb = new Scanner(System.in); 8 System.out.print("Input String: "); 9 String s = kb.nextline(); 0 s = s + " "; int pos = 0; while (pos >= 0) { 3 int start = pos; pos = s.indexof(" ", pos + ); 5 if (pos >= 0) { 6 String word = s.substring(start, pos); 7 word = word.trim(); 8 int count = CountVowels(word); 9 System.out.println("Word: " + word + " Count = " + count); 30 } 3 } 3 } 33 } 5

1 Short Answer (5 Points Each)

1 Short Answer (5 Points Each) 1 Short Answer (5 Points Each) 1. What are the three types of programming errors? Briefly describe each of them. Syntax Error: An error in the program code due to misuse of the programming language. Run-time

More information

1 Short Answer (10 Points Each)

1 Short Answer (10 Points Each) 1 Short Answer (10 Points Each) 1. Write a for loop that will calculate a factorial. Assume that the value n has been input by the user and have the loop create n! and store it in the variable fact. Recall

More information

1 Short Answer (10 Points Each)

1 Short Answer (10 Points Each) 1 Short Answer (10 Points Each) 1. For the following one-dimensional array, show the final array state after each pass of the three sorting algorithms. That is, after each iteration of the outside loop

More information

1 Short Answer (5 Points Each)

1 Short Answer (5 Points Each) 1 Short Answer (5 Points Each) 1. What are the three types of programming errors? Briefly describe each of them. Syntax Error: An error in the program code due to misuse of the programming language. Run-time

More information

1 Short Answer (5 Points Each)

1 Short Answer (5 Points Each) 1 Short Answer (5 Points Each) 1. Write a declaration of an array of 300 strings. String strarray[] = new String[300];. Write a method that takes in an integer n as a parameter and returns one half of

More information

1 Short Answer (5 Points Each)

1 Short Answer (5 Points Each) COSC 117 Exam #1 Solutions Fall 015 1 Short Answer (5 Points Each) 1. What is the difference between a compiler and an interpreter? Also, discuss Java s method. A compiler will take a program written in

More information

1 Short Answer (5 Points Each)

1 Short Answer (5 Points Each) 1 Short Answer (5 Points Each) 1. What are the three types of programming errors? Briefly describe each of them. Syntax Error: An error in the program code due to misuse of the programming language. Run-time

More information

5. What is a block statement? A block statement is a segment of code between {}.

5. What is a block statement? A block statement is a segment of code between {}. COSC 117 Exam 1 Key Fall 2012 Part 1: Definitions & Short Answer (3 Points Each) 1. What does CPU stand for? Central Processing Unit 2. Explain the difference between high-level languages and machine language.

More information

1 Short Answer (7 Points Each)

1 Short Answer (7 Points Each) 1 Short Answer ( Points Each) 1. Write a linear search method for an integer array that takes in an array and target value as parameters and returns the first position of the target in the array. If the

More information

5. What is a block statement? A block statement is a segment of code between {}.

5. What is a block statement? A block statement is a segment of code between {}. COSC 117 Exam 1 Key Fall 2012 Part 1: Definitions & Short Answer (3 Points Each) 1. What does CPU stand for? Central Processing Unit 2. Explain the difference between high-level languages and machine language.

More information

1 Definitions & Short Answer (4 Points Each)

1 Definitions & Short Answer (4 Points Each) Fall 013 Exam #1 Key COSC 117 1 Definitions & Short Answer ( Points Each) 1. Explain the difference between high-level languages and machine language. A high-level language is human readable code that

More information

Methods. world.my first method ( ) No variables. While ( wizard.t >= 0 ) wizard.method1. dragon. Methods. dragon.method1 ( ) No variables.

Methods. world.my first method ( ) No variables. While ( wizard.t >= 0 ) wizard.method1. dragon. Methods. dragon.method1 ( ) No variables. COSC 117 Exam 2 Key Spring 2011 Part 1: Alice Program Traces (10 Points Each) 1. Discuss what the following Alice program does from the point of view of the user, be very explicit. State what the user

More information

1 Short Answer (10 Points Each)

1 Short Answer (10 Points Each) Name: Write all of your responses on these exam pages. 1 Short Answer (10 Points Each) 1. What is the difference between a compiler and an interpreter? Also, discuss how Java accomplishes this task. 2.

More information

1 Definitions & Short Answer (5 Points Each)

1 Definitions & Short Answer (5 Points Each) Fall 2013 Final Exam COSC 117 Name: Write all of your responses on these exam pages. If you need more space please use the backs. Make sure that you show all of your work, answers without supporting work

More information

Final Exam Practice. Partial credit will be awarded.

Final Exam Practice. Partial credit will be awarded. Please note that this problem set is intended for practice, and does not fully represent the entire scope covered in the final exam, neither the range of the types of problems that may be included in the

More information

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks: كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this

More information

1 Short Answer (10 Points Each)

1 Short Answer (10 Points Each) COSC 117 Exam # Solutions Fall 01 1 Short Answer (10 Points Each) 1. Write a declaration for a two dimensional array of doubles that has 1 rows and 17 columns. Then write a nested for loop that populates

More information

Control Structures: if and while A C S L E C T U R E 4

Control Structures: if and while A C S L E C T U R E 4 Control Structures: if and while A C S - 1903 L E C T U R E 4 Control structures 3 constructs are essential building blocks for programs Sequences compound statement Decisions if, switch, conditional operator

More information

Java Classes: Math, Integer A C S L E C T U R E 8

Java Classes: Math, Integer A C S L E C T U R E 8 Java Classes: Math, Integer A C S - 1903 L E C T U R E 8 Math class Math class is a utility class You cannot create an instance of Math All references to constants and methods will use the prefix Math.

More information

1 Short Answer (2 Points Each)

1 Short Answer (2 Points Each) Fall 013 Exam # Key COSC 117 1 Short Answer ( Points Each) 1. What is the scope of a method/function parameter? The scope of a method/function parameter is in the method only, that is, it is local to the

More information

2. What are the two main components to the CPU and what do each of them do? 3. What is the difference between a compiler and an interpreter?

2. What are the two main components to the CPU and what do each of them do? 3. What is the difference between a compiler and an interpreter? COSC 117 Final Exam Spring 2011 Name: Part 1: Definitions & Short Answer (3 Points Each) 1. What do CPU and ALU stand for? 2. What are the two main components to the CPU and what do each of them do? 3.

More information

It is a constructor and is called using the new statement, for example, MyStuff m = new MyStuff();

It is a constructor and is called using the new statement, for example, MyStuff m = new MyStuff(); COSC 117 Exam 3 Key Fall 2012 Part 1: Definitions & Short Answer (3 Points Each) 1. A method in a class that has no return type and the same name as the class is called what? How is this type of method

More information

Unit 4: Classes and Objects Exercises

Unit 4: Classes and Objects Exercises Unit 4: Classes and Objects Exercises AP CS A 1. What is boolean a = 5 < 7; System.out.println( a ); 2. What does this display? boolean b = false; for ( int n = 1; n < 4; n++ ){ b =!b; System.out.print(

More information

AP Computer Science A

AP Computer Science A AP Computer Science A 1st Quarter Notes Table of Contents - section links Click on the date or topic below to jump to that section Date : 9/8/2017 Aim : Java Basics Objects and Classes Data types: Primitive

More information

Midterm Examination (MTA)

Midterm Examination (MTA) M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and

More information

CSC142, Computer Science II, Project 5 (2 nd submission)

CSC142, Computer Science II, Project 5 (2 nd submission) CSC142, Computer Science II, Project 5 (2 nd submission) Due via D2L. Late programs are not acceptable. Evaluation: Your score is given only when the program follows the given template and can fully support

More information

! definite loop: A loop that executes a known number of times. " The for loops we have seen so far are definite loops. ! We often use language like

! definite loop: A loop that executes a known number of times.  The for loops we have seen so far are definite loops. ! We often use language like Indefinite loops while loop! indefinite loop: A loop where it is not obvious in advance how many times it will execute.! We often use language like " "Keep looping as long as or while this condition is

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 1 Section 001 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

CS 101 Spring 2007 Midterm 2 Name: ID:

CS 101 Spring 2007 Midterm 2 Name:  ID: You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure

More information

AP COMPUTER SCIENCE A

AP COMPUTER SCIENCE A AP COMPUTER SCIENCE A CONTROL FLOW Aug 28 2017 Week 2 http://apcs.cold.rocks 1 More operators! not!= not equals to % remainder! Goes ahead of boolean!= is used just like == % is used just like / http://apcs.cold.rocks

More information

Introduction to Computer Science Unit 2. Notes

Introduction to Computer Science Unit 2. Notes Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and

More information

1. What is the difference between a compiler and an interpreter? Also, discuss Java s method.

1. What is the difference between a compiler and an interpreter? Also, discuss Java s method. Name: Write all of your responses on these exam pages. 1 Short Answer (5 Points Each) 1. What is the difference between a compiler and an interpreter? Also, discuss Java s method. 2. Java is a platform-independent

More information

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution Ch 5 Arrays Multiple Choice Test 01. An array is a ** (A) data structure with one, or more, elements of the same type. (B) data structure with LIFO access. (C) data structure, which allows transfer between

More information

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1 Name SOLUTION Page Points Score 2 15 3 8 4 18 5 10 6 7 7 7 8 14 9 11 10 10 Total 100 1 P age 1. Program Traces (41 points, 50 minutes)

More information

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a Spring 2017 Name: TUID: Page Points Score 1 28 2 18 3 12 4 12 5 15 6 15 Total: 100 Instructions The exam is closed book, closed notes. You may not use a calculator, cell phone, etc. i Some API Reminders

More information

AP Computer Science Unit 1. Programs

AP Computer Science Unit 1. Programs AP Computer Science Unit 1. Programs Open DrJava. Under the File menu click on New Java Class and the window to the right should appear. Fill in the information as shown and click OK. This code is generated

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

Unit 4: Classes and Objects Notes

Unit 4: Classes and Objects Notes Unit 4: Classes and Objects Notes AP CS A Another Data Type. So far, we have used two types of primitive variables: ints and doubles. Another data type is the boolean data type. Variables of type boolean

More information

Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8. Handout 5. Loops.

Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8. Handout 5. Loops. Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8 Handout 5 Loops. Loops implement repetitive computation, a k a iteration. Java loop statements: while do-while for 1. Start with the while-loop.

More information

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 Question One: Choose the correct answer and write it on the external answer booklet. 1. Java is. a. case

More information

CS141 Programming Assignment #5

CS141 Programming Assignment #5 CS141 Programming Assignment #5 Due Wednesday, Nov 16th. 1) Write a class that asks the user for the day number (0 to 6) and prints the day name (Saturday to Friday) using switch statement. Solution 1:

More information

Assignment 2.4: Loops

Assignment 2.4: Loops Writing Programs that Use the Terminal 0. Writing to the Terminal Assignment 2.4: Loops In this project, we will be sending our answers to the terminal for the user to see. To write numbers and text to

More information

Fundamentals of Programming Data Types & Methods

Fundamentals of Programming Data Types & Methods Fundamentals of Programming Data Types & Methods By Budditha Hettige Overview Summary (Previous Lesson) Java Data types Default values Variables Input data from keyboard Display results Methods Operators

More information

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Page 0 German University in Cairo April 6, 2017 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Bar Code

More information

Introduction to Computer Science Unit 2. Notes

Introduction to Computer Science Unit 2. Notes Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and

More information

Lecture 8 " INPUT " Instructor: Craig Duckett

Lecture 8  INPUT  Instructor: Craig Duckett Lecture 8 " INPUT " Instructor: Craig Duckett Assignments Assignment 2 Due TONIGHT Lecture 8 Assignment 1 Revision due Lecture 10 Assignment 2 Revision Due Lecture 12 We'll Have a closer look at Assignment

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ OBJECT-ORIENTED PROGRAMMING IN JAVA 2 Programming

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #04: Fall 2015 1/20 Office hours Monday, Wednesday: 10:15 am to 12:00 noon Tuesday, Thursday: 2:00 to 3:45 pm Office: Lindley Hall, Room 401C 2/20 Printing

More information

COE 212 Engineering Programming. Welcome to Exam II Tuesday November 28, 2018

COE 212 Engineering Programming. Welcome to Exam II Tuesday November 28, 2018 1 COE 212 Engineering Programming Welcome to Exam II Tuesday November 28, 2018 Instructors: Dr. Dima El-khalil Dr. Jawad Fahs Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam

More information

Introduction to Computer Science Unit 2. Exercises

Introduction to Computer Science Unit 2. Exercises Introduction to Computer Science Unit 2. Exercises Note: Curly brackets { are optional if there is only one statement associated with the if (or ) statement. 1. If the user enters 82, what is 2. If the

More information

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution Ch 5 Arrays Multiple Choice 01. An array is a (A) (B) (C) (D) data structure with one, or more, elements of the same type. data structure with LIFO access. data structure, which allows transfer between

More information

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below. C212 Early Evaluation Exam Mon Feb 10 2014 Name: Please provide brief (common sense) justifications with your answers below. 1. What is the type (and value) of this expression: 5 * (7 + 4 / 2) 2. What

More information

Object Oriented Programming. Java-Lecture 6 - Arrays

Object Oriented Programming. Java-Lecture 6 - Arrays Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types

More information

Practice Problems: Instance methods

Practice Problems: Instance methods Practice Problems: Instance methods Submit your java files to D2L. Late work will not be acceptable. a. Write a class Person with a constructor that accepts a name and an age as its argument. These values

More information

Controls Structure for Repetition

Controls Structure for Repetition Controls Structure for Repetition So far we have looked at the if statement, a control structure that allows us to execute different pieces of code based on certain conditions. However, the true power

More information

CS 455 Midterm Exam 1 Spring 2013 [Bono] Feb. 21, 2013

CS 455 Midterm Exam 1 Spring 2013 [Bono] Feb. 21, 2013 Name: USC loginid (e.g., ttrojan): CS 455 Midterm Exam 1 Spring 2013 [Bono] Feb. 21, 2013 There are 5 problems on the exam, with 54 points total available. There are 7 pages to the exam, including this

More information

Practice Midterm 1. Problem Points Score TOTAL 50

Practice Midterm 1. Problem Points Score TOTAL 50 CS 120 Software Design I Spring 2019 Practice Midterm 1 University of Wisconsin - La Crosse February 25 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages including the

More information

COE 211 Computer Programming. Welcome to Exam I Tuesday March 13, 2018

COE 211 Computer Programming. Welcome to Exam I Tuesday March 13, 2018 1 COE 211 Computer Programming Welcome to Exam I Tuesday March 13, 2018 Instructors: Dr. Dima El-khalil Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book. Please do not forget

More information

CS 101 Exam 2 Spring Id Name

CS 101 Exam 2 Spring Id Name CS 101 Exam 2 Spring 2005 Email Id Name This exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points,

More information

CSE 1223: Exam II Autumn 2016

CSE 1223: Exam II Autumn 2016 CSE 1223: Exam II Autumn 2016 Name: Instructions: Do not open the exam before you are told to begin. This exam is closed book, closed notes. You may not use any calculators or any other kind of computing

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 1 Section 003 Fall 2013 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

AP CS Unit 3: Control Structures Notes

AP CS Unit 3: Control Structures Notes AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts

More information

CSE 142 Sample Midterm Exam #3

CSE 142 Sample Midterm Exam #3 CSE 142 Sample Midterm Exam #3 1. Expressions (10 points) For each expression in the left-hand column, indicate its value in the right-hand column. Be sure to list a constant of appropriate type (e.g.,

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 1 Section 001 Spring 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2. Jan Baumbach. DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net COURSE ORGANIZATION 2 Course Elements Lectures: 10 lectures Find schedule and class rooms in online

More information

Place your name tag here

Place your name tag here CS 170 Exam 1 Section 001 Spring 2015 Name: Place your name tag here Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with

More information

Section 002 Spring CS 170 Exam 1. Name (print): Instructions:

Section 002 Spring CS 170 Exam 1. Name (print): Instructions: CS 170 Exam 1 Section 002 Spring 2015 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

CS212 Midterm. 1. Read the following code fragments and answer the questions.

CS212 Midterm. 1. Read the following code fragments and answer the questions. CS1 Midterm 1. Read the following code fragments and answer the questions. (a) public void displayabsx(int x) { if (x > 0) { System.out.println(x); return; else { System.out.println(-x); return; System.out.println("Done");

More information

Decisions (If Statements) And Boolean Expressions

Decisions (If Statements) And Boolean Expressions Decisions (If Statements) And Boolean Expressions CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Last updated: 2/15/16 1 Syntax if (boolean_expr)

More information

Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks:

Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks: كلية الحاسبات وتقنية المعلوما Exam 1 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: October 18, 2015 Student Name: Student ID: Total Marks: 45 Obtained Marks: Instructions: Do not open this

More information

Selection Statements and operators

Selection Statements and operators Selection Statements and operators CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/

More information

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination Monday, March 9, 2009 Examiners: Mathieu Petitpas [Section 1] 18:30

More information

b. Suppose you enter input from the console, when you run the program. What is the output?

b. Suppose you enter input from the console, when you run the program. What is the output? Part I. Show the printout of the following code: (write the printout next to each println statement if the println statement is executed in the program). a. Show the output of the following code: public

More information

Java Classes: Random, Character A C S L E C T U R E 6

Java Classes: Random, Character A C S L E C T U R E 6 Java Classes: Random, Character A C S - 1903 L E C T U R E 6 Random An instance of the Random can be used to generate a stream of random values Typical process: 1. Create a Random object 2. Use the object

More information

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8 Today... Java basics S. Bowers 1 of 8 Java main method (cont.) In Java, main looks like this: public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World!"); Q: How

More information

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to define and invoke void and return java methods JAVA

More information

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination Tuesday, November 4, 2008 Examiners: Mathieu Petitpas [Section 1] 18:30

More information

Selection Statements and operators

Selection Statements and operators Selection Statements and operators CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/

More information

CSC 231 DYNAMIC PROGRAMMING HOMEWORK Find the optimal order, and its optimal cost, for evaluating the products A 1 A 2 A 3 A 4

CSC 231 DYNAMIC PROGRAMMING HOMEWORK Find the optimal order, and its optimal cost, for evaluating the products A 1 A 2 A 3 A 4 CSC 231 DYNAMIC PROGRAMMING HOMEWORK 10-1 PROFESSOR GODFREY MUGANDA 1. Find the optimal order, and its optimal cost, for evaluating the products where A 1 A 2 A 3 A 4 A 1 is 10 4 A 2 is 4 5 A 3 is 5 20

More information

CS1150 Principles of Computer Science Arrays

CS1150 Principles of Computer Science Arrays CS1150 Principles of Computer Science Arrays Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Opening Problem Read one hundred numbers, compute their

More information

Lab Exercise 1. Objectives: Part 1. Introduction

Lab Exercise 1. Objectives: Part 1. Introduction Objectives: king Saud University College of Computer &Information Science CSC111 Lab Object II All Sections - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

More information

CCHS Math Recursion Worksheets M Heinen CS-A 12/5/2013. Recursion Worksheets Plus Page 1 of 6

CCHS Math Recursion Worksheets M Heinen CS-A 12/5/2013. Recursion Worksheets Plus Page 1 of 6 CS-A // arraysol[][] = r; import java.util.scanner; public class RecursionApp { static int r; // return value static int[][] arraysol = new int[][7]; // create a solution array public static void main(string[]

More information

Program Control Flow

Program Control Flow Lecture slides for: Chapter 3 Program Control Flow Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2

More information

Program Control Flow

Program Control Flow Lecture slides for: Chapter 3 Program Control Flow Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2

More information

CMPS 11 Introduction to Programming Midterm 1 Review Problems

CMPS 11 Introduction to Programming Midterm 1 Review Problems CMPS 11 Introduction to Programming Midterm 1 Review Problems Note: The necessary material for some of these problems may not have been covered by end of class on Monday, the lecture before the exam. If

More information

COMP-202. Recursion. COMP Recursion, 2011 Jörg Kienzle and others

COMP-202. Recursion. COMP Recursion, 2011 Jörg Kienzle and others COMP-202 Recursion Recursion Recursive Definitions Run-time Stacks Recursive Programming Recursion vs. Iteration Indirect Recursion Lecture Outline 2 Recursive Definitions (1) A recursive definition is

More information

COE 212 Engineering Programming. Welcome to the Final Exam Monday May 18, 2015

COE 212 Engineering Programming. Welcome to the Final Exam Monday May 18, 2015 1 COE 212 Engineering Programming Welcome to the Final Exam Monday May 18, 2015 Instructors: Dr. Joe Tekli Dr. George Sakr Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book.

More information

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F.

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F. 1 COE 212 Engineering Programming Welcome to Exam II Thursday April 21, 2016 Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book.

More information

Tutorial 12. Exercise 1: Exercise 2: CSC111 Computer Programming I

Tutorial 12. Exercise 1: Exercise 2: CSC111 Computer Programming I College of Computer and Information Sciences CSC111 Computer Programming I Exercise 1: Tutorial 12 Arrays: A. Write a method add that receives an array of integers arr, the number of the elements in the

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

x++ vs. ++x x=y++ x=++y x=0; a=++x; b=x++; What are the values of a, b, and x?

x++ vs. ++x x=y++ x=++y x=0; a=++x; b=x++; What are the values of a, b, and x? x++ vs. ++x x=y++ x=++y x=0; a=++x; b=x++; What are the values of a, b, and x? x++ vs. ++x public class Plus{ public static void main(string []args){ int x=0; int a=++x; System.out.println(x); System.out.println(a);

More information

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name:

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name: CSC 1051 Algorithms and Data Structures I Final Examination May 2, 2015 Name: Question Value 1 10 Score 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 20 TOTAL 100 Please answer questions in the spaces provided.

More information

COMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements

COMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements COMP-202 Unit 4: Programming With Iterations CONTENTS: The while and for statements Introduction (1) Suppose we want to write a program to be used in cash registers in stores to compute the amount of money

More information

COE 212 Engineering Programming. Welcome to Exam II Friday November 27, 2015

COE 212 Engineering Programming. Welcome to Exam II Friday November 27, 2015 1 COE 212 Engineering Programming Welcome to Exam II Friday November 27, 2015 Instructors: Dr. Salim Haddad Dr. Bachir Habib Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam

More information

King Saud University College of Computer and Information Sciences Computer Science Department

King Saud University College of Computer and Information Sciences Computer Science Department King Saud University College of Computer and Information Sciences Computer Science Department Course Code: CSC 111 Course Title: Introduction to Programming Semester: Fall 2017-2018 Exercises Cover Sheet:

More information

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Simple Control Flow: if-else statements

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Simple Control Flow: if-else statements WIT COMP1000 Simple Control Flow: if-else statements Control Flow Control flow is the order in which program statements are executed So far, all of our programs have been executed straight-through from

More information

Midterm Practice Problems - answer key Answers appear in boldface.

Midterm Practice Problems - answer key Answers appear in boldface. Part 1. (a) Consider the following code segment: int p = 30; int b; Midterm Practice Problems - answer key Answers appear in boldface. System.out.print( Please enter an integer ); b = kb.nextint(); if

More information

CS1150 Principles of Computer Science Math Functions, Characters and Strings (Part II)

CS1150 Principles of Computer Science Math Functions, Characters and Strings (Part II) CS1150 Principles of Computer Science Math Functions, Characters and Strings (Part II) Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs How to generate

More information

Tutorial 03. Exercise 1: CSC111 Computer Programming I

Tutorial 03. Exercise 1: CSC111 Computer Programming I College of Computer and Information Sciences CSC111 Computer Programming I Exercise 1: Tutorial 03 Input & Output Operators Expressions A. Show the result of the following code: 1.System.out.println(2

More information

Installing Java. Tradition. DP Computer Science Unit 4.3: Intro to programming 1/17/2018. Software & websites

Installing Java. Tradition. DP Computer Science Unit 4.3: Intro to programming 1/17/2018. Software & websites DP Computer Science Unit 4.3: Intro to programming Installing Java Software & websites JDK (Java development kit) download: http://www.oracle.com/technetwork/java/javase/ Tradition For a full IDE (integrated

More information