Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 26, 2017

Similar documents
Exam 2. CSC 121 MW Class. Lecturer: Howard Rosenthal. April 25, 2016

Exam 2. CSC 121 TTH Class. Lecturer: Howard Rosenthal. April 26, 2016

2. Each element of an array is accessed by a number known as a(n) a. a. subscript b. size declarator c. address d. specifier

All answers will be posted on web site, and most will be reviewed in class.

Final Exam. CSC 121 Fall Lecturer: Howard Rosenthal. Dec. 13, 2017

Final Exam. CSC 121 Spring Lecturer: Howard Rosenthal. May 17, 2017

Test 1. CSC 121 Lecture Lecturer: Howard Rosenthal. March 4, 2014

Final Exam. CSC 121 Spring 2016 TTH. Lecturer: Howard Rosenthal. May 17, 2016

Exam 1. CSC 121 Spring Lecturer: Howard Rosenthal. March 1, 2017

Final Exam. CSC 121 Fall Lecturer: Howard Rosenthal. Dec. 13, 2017

CS313D: ADVANCED PROGRAMMING LANGUAGE

Exam 1 Answer Key CSC 123 Fall 2018 Lecturer: Howard Rosenthal Oct. 17, 2018

CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II

Final Exam. CSC 121 Fall 2015 TTH. Lecturer: Howard Rosenthal. Dec. 15, 2015

2/3/2018 CS313D: ADVANCED PROGRAMMING LANGUAGE. Lecture 3: C# language basics II. Lecture Contents. C# basics. Methods Arrays. Dr. Amal Khalifa, Spr17

Final Exam. CSC 121 Fall 2015 MW. Lecturer: Howard Rosenthal. Dec. 16, 2015

Introduction to Programming Using Java (98-388)

Computer Programming: C++

Final Exam. COMP Summer I June 26, points

Arrays and Lists CSC 121 Fall 2015 Howard Rosenthal

CSC Java Programming, Fall Java Data Types and Control Constructs

Exam 3 Chapters 7 & 9

Arrays and Lists CSC 121 Fall 2016 Howard Rosenthal

Arrays and Lists CSC 121 Fall 2014 Howard Rosenthal

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

ECE 122. Engineering Problem Solving with Java

Arrays and Lists Review CSC 123 Fall 2018 Howard Rosenthal

Arrays. Lecture 11 CGS 3416 Fall October 26, 2015

Chapter 9 Introduction to Arrays. Fundamentals of Java

Arrays. Lecture 11 CGS 3416 Spring March 6, Lecture 11CGS 3416 Spring 2017 Arrays March 6, / 19

Computational Expression

CS111: PROGRAMMING LANGUAGE II

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Computer Science is...

Introduction to Computer Science Midterm 3 Fall, Points

CSCE 206: Structured Programming in C++

CS 12 Fall 2003 Solutions for mid-term exam #2

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question

Review for Test 1 (Chapter 1-5)

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Array. Array Declaration:

Array. Prepared By - Rifat Shahriyar

Object Oriented Programming. Java-Lecture 6 - Arrays

Getting started with Java

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

Selected Questions from by Nageshwara Rao

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Chapter 6 Single-Dimensional Arrays. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1)

Lesson 06 Arrays. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

CSC 307 DATA STRUCTURES AND ALGORITHM ANALYSIS IN C++ SPRING 2011

Arrays. Introduction to OOP with Java. Lecture 06: Introduction to OOP with Java - AKF Sep AbuKhleiF - 1

New York University Intro to Computer Science (CSCI-UA.101) Fall 2014 Midterm #1 Test G. Instructions:

array Indexed same type

Arrays: Higher Dimensional Arrays. CS0007: Introduction to Computer Programming

COS 126 General Computer Science Spring Written Exam 1

Review Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous

Chapter 2: Basic Elements of Java

Lecture 5: Methods CS2301

Pointers. Memory. void foo() { }//return

Chapter 2: Using Data

Computing Science 114 Solutions to Midterm Examination Tuesday October 19, In Questions 1 20, Circle EXACTLY ONE choice as the best answer

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

PROGRAMMING FUNDAMENTALS

FORM 2 (Please put your name and form # on the scantron!!!!)

Use the Scantron sheets to write your answer. Make sure to write your Purdue ID (NOT Purdue Login ID) and your name on the Scantron answer sheet.

Le L c e t c ur u e e 3 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Control Statements

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

High Institute of Computer Science & Information Technology Term : 1 st. El-Shorouk Academy Acad. Year : 2013 / Year : 2 nd

Chapter 6 SINGLE-DIMENSIONAL ARRAYS

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Programming: Java. Chapter Objectives. Chapter Objectives (continued) Program Design Including Data Structures. Chapter 7: User-Defined Methods

Lecture 15. Arrays (and For Loops)

ECE 30 Introduction to Computer Engineering

Announcements. PS 3 is due Thursday, 10/6. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am

Computer Science & Engineering 150A Problem Solving Using Computers

Tutorial 11. Exercise 1: CSC111 Computer Programming I. A. Write a code snippet to define the following arrays:

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

An Introduction To Writing Your Own Classes CSC 123 Fall 2018 Howard Rosenthal

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

Last Class. Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it

Instructor: Eng.Omar Al-Nahal

APCS Semester #1 Final Exam Practice Problems

ECE 122. Engineering Problem Solving with Java

Declaring a 2D Array

Principles of Programming. Chapter 6: Arrays

Language Reference Manual

CS1004: Intro to CS in Java, Spring 2005

Array Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)

Last Class. More on loops break continue A bit on arrays

Lecture 2. Examples of Software. Programming and Data Structure. Programming Languages. Operating Systems. Sudeshna Sarkar

CS 3360 Design and Implementation of Programming Languages. Exam 1

Introduction to Programming (Java) 4/12

Objects and Classes Lecture 2

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

Transcription:

Your Name: Exam 2. CSC 121 MW Class Lecturer: Howard Rosenthal April 26, 2017 The following questions (or parts of questions) in numbers 1-7 are all worth 3 points each. 1. Answer the following as true or false. a. _F_ Every for iteration loop must be executed at least once. b. _T_ Iterative statements can be nested. c. _T_ Two array reference variables can refer to the same array object. d. _F_ An array in Java can only store primitive data types (i.e. be declared as a primitive data type). e. _F_ A two-dimensional array can hold different value types in different rows. f. _T_ Any iteration that you can perform with a while statement can also be performed with a do-while statement. g. _F_ Java does not allow void methods to be overloaded. h. _F_ All methods must be called from the main method. i. _T_ A list must always be ordered before performing a binary search. j. _F_ The index of an array can be of type long. k. _T_ The output from the java compiler is expressed in Bytecode. 2. Given the following initialization int [][] array1 = new int [8][4]; The value array1.length is 8. 3. The number of bytes reserved for the array double [][] newarray = new double [3][5] is 120 4. Write a statement that declares and instantiates a char array called letterarray of length 14. char [] letterarray = new char[14]; 1

5. Give two different examples of method overloading that display two different ways that methods can be overloaded. (Each example requires two method headers with the same name) a. b. public static void method1() public static void method1(int x) public static double method2(int x, double y) public static double method2(int x, int y) 6. Write a single statement the declares, instantiates and initializes a ragged array of type int called myarray equivalent to the following table: 1 0-5 8 1 1 3-6 9 12 4 int [][] myarray = { {1}, {0,-5}, {8, 1, 1, 3, -6}, {9, 12, 4}}; 2

7. What are the values stored in the array a after the following code executes: int [] a = new int [5]; for (int i = 1; i < a.length; i++) { a[i] = i; a[i] = (a[i-1]+a[i]) +2; } 0, 3, 7, 12, 18 8. What is the printout from the code segment below: int [] ref1 = new int [6]; int [] ref2; for (int i=0; i < 6; i++) ref1[i] = (int)math.pow(i,2); ref2 = ref1; for (int i=0; i < 6; i++) ref2[i] =2*ref2[i]; for (int i=0; i < 6; i++) System.out.print(ref1[i] + ); 0 2 8 18 32 50 3

Programs: It is important to follow the instructions in each problem. Note: The second problem is on page 5. e-mail two.java files to csc121csudh@gmail.com Do not mail these files until you are done with the entire exam. No second mailing will be allowed 1. Compare (16 points) Write a class called Compare with the main method and greaterzero method as described below. The main method does the following: a. Reads in three integer values. b. Calls greaterzero, c. Prints out the three integers and the value that is returned by greaterzero as follows: It is booleanvalue that the integers num1, num2 and num3 are all greater than zero. Note: Italicized parts are replaced with actual values greaterzero does the following: a. Has three int variables as formal parameters b. Returns the value true if all three integers are all greater than 0, false otherwise. It is true that the integers 1, 4 and 7 are all greater than zero. It is false that the integers 0, 3 and 9 are all greater than zero. It is false that the integers 6, -1 and 8 are all greater than zero. It is false that the integers 4, 7 and -2 are all greater than zero. 4

2. CountPositive (32) Write a class CountPositive that does the following: The main method does the following: a. Requests from the user the dimensions for a two dimensional array. b. Calls the method createarray to create a two-dimensional integer array. c. Calls a method fullarray with a reference to the array created by createarray. d. Calls a method called greaterten with a reference to the array created by createarray. e. Prints out the final elements of the two-dimensional array row by row. f. The main method then prints out the final values in the array and a final sentence stating: g. It is (true/false) that there are more entries in the array greater than ten than less than or equal to ten. createarray does the following: a. Accepts the dimensions of a two dimensional int array as parameters. b. Creates a two-dimensional int array using the input parameters. c. Returns a reference to the array that was created. fullarray does the following: a. Has a two-dimensional int array as its formal parameter. b. Fills a two-dimensional int array with random integers from 1 to 20. greaterten does the following: a. Has a two-dimensional int array as its formal parameter. b. It then counts the number of entries greater than ten and returns true if there are more numbers greater than ten in the array. Otherwise it returns false. Please enter the rows and columns in a dimensional integer array 3 4 20 5 5 9 18 4 18 15 9 11 8 20 It is false that there are more entries in the array greater than ten than less than or equal to ten Please enter the rows and columns in a dimensional integer array 3 4 6 6 13 2 16 16 20 18 15 20 12 20 It is true that there are more entries in the array greater than ten than less than or equal to ten 5

6

7

8