CS 101 Fall 2006 Midterm 1 Name: ID:

Similar documents
CS 101 Spring 2007 Midterm 2 Name: ID:

CS 101 Fall 2006 Midterm 3 Name: ID:

CS 101 Fall 2005 Midterm 2 Name: ID:

CS 101 Spring 2006 Final Exam Name: ID:

Chapter 9 Lab Text Processing and Wrapper Classes

This exam is open book. Each question is worth 3 points.

CSE 1223: Exam II Autumn 2016

Lab5. Wooseok Kim

Programming with Java

Midterms Save the Dates!

CS 101 Exam 1 Spring 200 Id Name

Computational Expression

CS 231 Data Structures and Algorithms, Fall 2016

Array. Prepared By - Rifat Shahriyar

CS 177 Week 15 Recitation Slides. Review

Intro to Programming in Java Practice Midterm

CS61BL. Lecture 1: Welcome to CS61BL! Intro to Java and OOP Testing Error-handling

H212 Introduction to Software Systems Honors

CS 112 Midterm Exam Fall 2016

Practice Midterm 1. Problem Points Score TOTAL 50

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

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

Fundamentals of Programming Data Types & Methods

Midterm Exam 2 CS 455, Fall 2013

Question: Total Points: Score:

CS 251 Intermediate Programming Java Basics

1B1b Classes in Java Part I

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

Midterms Save the Dates!

More on Arrays CS 16: Solving Problems with Computers I Lecture #13

Final Exam. COMP Summer I June 26, points

Page 1 / 3. Page 2 / 18. Page 3 / 8. Page 4 / 21. Page 5 / 15. Page 6 / 20. Page 7 / 15. Total / 100. Pledge:

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Java Fall 2018 Margaret Reid-Miller

CS 177 Recitation. Week 8 Methods

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

Java Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2

(the bubble footer is automatically inserted in this space)

COS 126 General Computer Science Spring Written Exam 1

Lecture 6. Assignments. Summary - Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4

Lecture 6. Assignments. Java Scanner. User Input 1/29/18. Reading: 2.12, 2.13, 3.1, 3.2, 3.3, 3.4

2: Basics of Java Programming

Practice Midterm 1 Answer Key

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

CS 2150 Final Exam, Spring 2018 Page 1 of 10 UVa userid:

CS 101 Exam 2 Spring Id Name

Lab5. Wooseok Kim

You ll be reading more about tools for branching in Sections 3.4, and We are skipping Sections 3.5, 3.11 and 3.13-end of chapter.

CS 216 Fall 2007 Final Exam Page 1 of 10 Name: ID:

CS 1063 Introduction to Computer Programming Midterm Exam 2 Section 1 Sample Exam

Midterm Exam CS 251, Intermediate Programming March 6, 2015

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

Darrell Bethea May 25, 2011

Getting started with Java

Computer Science 145 Midterm 1 Fall 2016

Reviewing all Topics this term

CMSC 331 Second Midterm Exam

Getting started with Java

Controls Structure for Repetition

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

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

Question: Total Points: Score:

Computer Science II Data Structures

Objects and Classes. 1 Creating Classes and Objects. CSCI-UA 101 Objects and Classes

Please answer the following questions. Do not re-code the enclosed codes if you have already completed them.

(the bubble footer is automatically inserted in this space)

Flow of Control. Chapter 3

(the bubble footer is automatically inserted into this space)

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

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

Key Java Simple Data Types

Announcements. 1. Forms to return today after class:

Part 1 (80 points) Multiple Choice Questions (20 questions * 4 points per question = 80 points)

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

CMPSCI 250: Introduction to Computation. Lecture #1: Things, Sets and Strings David Mix Barrington 22 January 2014

Arrays and Lists CSC 121 Fall 2014 Howard Rosenthal

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

Name Section Number. CS210 Exam #2 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

CS 2150 Exam 1, Spring 2018 Page 1 of 6 UVa userid:

1. An operation in which an overall value is computed incrementally, often using a loop.

CS170 (005): Introduction to Computer Science Exam 2

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

Lec 3. Compilers, Debugging, Hello World, and Variables

(the bubble footer is automatically inserted into this space)

Prelim One Solution. CS211 Fall Name. NetID

Example Program. public class ComputeArea {

CS16 Midterm Exam 2 E02, 09F, Phill Conrad, UC Santa Barbara Wednesday, 11/18/2009

Give one example where you might wish to use a three dimensional array

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING

4. Java language basics: Function. Minhaeng Lee

CS11 Java. Fall Lecture 1

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

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

The for Loop, Accumulator Variables, Seninel Values, and The Random Class. CS0007: Introduction to Computer Programming

C Sc 227 Project 1: Three Main Methods

Compiling and Running a C Program in Unix

Flow of Control. Chapter 3

CS56 final (E03) W15, Phill Conrad, UC Santa Barbara Wednesday, 03/18/2015. Name: Umail umail.ucsb.edu. Circle one: 4pm 5pm 6pm

Transcription:

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 to look over all the questions and plan your time accordingly. Please sign the honor pledge here: Page 1 / 3 Page 2 / 16 Page 3 / 25 Page 4 / 13 Page 5 / 8 Page 6 / 15 Page 7 / 20 Page 8 XX / XX Total / 100 Note: When an integer type is required use int, when a floating-point type is required use double. If we don t specify an aspect of the problem, you can choose it. Note: If you are still writing on the exam after pens down is called even if it is just to write your name then you will receive a zero on this exam. No exceptions! 1. [3 points] What lab section are you in? CS 101-E CS 101-2 (lab 7:00 8:30 p.m. Thu) CS 101-3 (lab noon 1:30 p.m. Fri) CS 101-4 (lab 2:00 3:30 p.m. Fri) CS 101-5 (lab 10:00 11:30 a.m. Fri) CS 101-6 (lab 2:00 3:30 p.m. Thu) Page 1 of 8

2. [8 points] Consider the following now familiar statement in the Java language: Scanner stdin = new Scanner(System.in); Answer the following as true or false (don t answer T or F you need to write the FULL word to get credit). a. Scanner is the name of an object, not a class. Answer: b. The word stdin is a Java reserved word. Answer: c. The word new can be the name of a variable. Answer: d. The word New can be the name of a variable (notice the capitalization) Answer: 3. [8 points] Consider the following statement: double x = 3 / 2; a. What does the = sign do in this statement? b. What value and type of value does the expression to the right of the = sign evaluate to? c. What value ends up being stored in x? / 16 Page 2 of 8

4. [10 points] Consider each of the following Java statements. For each one, state the value that will be stored in the variable AND state it s type. If the statement will cause an error, state so. a. char a = a ; b. String s = s ; c. int i =1 + zero ; d. String t =1 + zero ; e. int j = 1 + 2 + 3 + 4 + 5; f. String grok = Fred + (21 + 6 % 2); 5. [15 points] What is the value AND TYPE of each of the following Java expressions? a. 2 / 3 e. 21 % 8 % 5 b. 2.0 / 3 f. (21 % 8) % 5 c. 2.0 / 3.0 g.!true && false d. 2 / 3 * 4.0 h.!true true / 25 Page 3 of 8

6. [8 points] Consider each of the following names. a. int b. String c. InputStream d. Scanner e. boolean f. real character g. floater h. longish i. zero j. shorty k. double l. bite m. vector n. logical o. physical Which of the above types are Java primitive types (also sometimes called built-in types)? Be careful of the spelling! You can circle your answers or write them out. 7. [5 points] Consider the following code sequence. What are the values of the variables x, y and z after this code runs? int x; x = 7; int y; y = 3; int z; z = 5; y = z; z = 4; x s value: y s value: z s value: / 13 Page 4 of 8

8. [5 points] Consider the following code sequence. At the end of this sequence, can the String object referenced by the variable s at the beginning of the code segment be garbage-collected? Explain in one brief sentence why or why not. String s = new String( Hello, I m a string. ); String t = s; s = null; 9. [3 points] A type in Java (and in other similar programming languages, by the way) defines a range of possible values and a set of operations that can be performed on values of that type. For each of the following types, give an example of a possible value of the type and an example of a possible operation on such a value: a. int b. String c. boolean / 8 Page 5 of 8

10. [15 points] Given the following String declaration, which lists each character in the alphabet: String alphabet = abcdefghijklmnopqrstuvwxyz ; What value does each of the following code segments evaluate to? If they result in an error, then state so. Don t worry about the lack of semi-colons, however. a. alphabet.substring (3,4) b. alphabet.substring (6) c. alphabet.substring (30) d. alphabet.indexof ( c ) e. alphabet.indexof ( 6 ) f. alphabet.trim() g. alphabet.charat(3) h. alphabet.length() / 15 Page 6 of 8

11. [20 points] Write a complete Java program in the space below that performs ALL of the following steps: a. Read in a String from the keyboard (you can use any of Scanner s methods that will obtain a String) b. Read in TWO integers from the keyboard c. Compute the product of those two integers. You can assume that the first integer read in will be less than or equal to the second (i.e. they will be entered in sorted order) d. Compute the substring from the first entered integer to the second entered integer (you can assume that the values entered will be valid values) e. Print out both computed results: the product and the substring You don t have to worry about any of the good programming practices that are normally done in the homeworks. This means you don t have to comment your code. There is skeleton code on the back of this page, and you should write your program there. You only need to write the code that goes inside the main() method. Write your answer on the back of this page. / 20 Page 7 of 8

import java.util.*; public class Midterm1 { public static void main (String[] args) { } } XX / XX Page 8 of 8