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

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

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

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

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

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

Chapter 2: Using Data

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

Introduction to Computer Science, Winter Term Practice Assignment 3 Discussion:

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

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Primitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long

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

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Constants and Variables

COMP Primitive and Class Types. Yi Hong May 14, 2015

Ex: If you use a program to record sales, you will want to remember data:

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

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

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS 11 java track: lecture 1

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

Chapter 2: Basic Elements of Java

ESc101 : Fundamental of Computing

Programming with Java

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

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

Review for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure

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

Le L c e t c ur u e e 2 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 Variables Operators

SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017

CSCI 1103: Input with TextIO

PROGRAMMING FUNDAMENTALS

1.3b Type Conversion

Lecture Set 4: More About Methods and More About Operators

Review for Test 1 (Chapter 1-5)

Chapter 1. Introduction to Computers and Programming. M hiwa ahmad aziz

VARIABLES AND TYPES CITS1001

JAVA OPERATORS GENERAL

Lecture 1. Types, Expressions, & Variables

Introduction to Programming Using Java (98-388)

More Programming Constructs -- Introduction

Operators. Java operators are classified into three categories:

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Chapter 6 Primitive types

Values, Variables, Types & Arithmetic Expressions. Agenda

Computational Expression

CS101 PLEDGED SPRING 2001

CIS 110: Introduction to Computer Programming

Lecture Set 4: More About Methods and More About Operators

Basic Operations jgrasp debugger Writing Programs & Checkstyle

ECE 122 Engineering Problem Solving with Java

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Full file at

LECTURE 3 C++ Basics Part 2

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

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

Department of Computer Science Purdue University, West Lafayette

Chapter 2: Using Data

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

(a) This midterm exam is very easy! (b) In Java the return value of a method can be ignored.

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Exercise: Using Numbers

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Full file at

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

Basics of Java Programming

Getting started with Java

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Java Programming Language. 0 A history

Values and Variables 1 / 30

Accelerating Information Technology Innovation

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

CSC Java Programming, Fall Java Data Types and Control Constructs

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Operators. Lecture 3 COP 3014 Spring January 16, 2018

Java is an objet-oriented programming language providing features that support

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

Prof. Navrati Saxena TA: Rochak Sachan

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

An Introduction to Computers and Java CSC 121 Spring 2015 Howard Rosenthal

I. True/False: (2 points each)

CST112 Variables Page 1

Processor. Lecture #2 Number Rep & Intro to C classic components of all computers Control Datapath Memory Input Output

The Arithmetic Operators

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

Java Fall 2018 Margaret Reid-Miller

Operators and Expressions

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Exam 3 Chapters 7 & 9

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

Computer Components. Software{ User Programs. Operating System. Hardware

Transcription:

1 Test 1. CSC 121 Lecture 21199 Lecturer: Howard Rosenthal March 4, 2014 Your Name: KEY The following questions (or parts of questions) in numbers 1-16 are all worth 2 points each. 1. Fill in the following table for the 8 primitive data types. Spell the types exactly correctly.(16 points total) Data Type Number of Bytes byte 1 short 2 int 4 long 8 float 4 double 8 char 2 boolean 1 1. Answer the following as true or false a. Retrieving data from RAM usually takes more time than retrieving data from a hard drive. F b. A compiler translates source code into machine instructions. T c. The statement int byte = 350 generates an error. T d. If x has type int and y has type float, then the assignment y=x; is legal. T e. (true&&false) always evaluates as false. T f. Every if must have a corresponding else. F g. ( AB == ( A + B )) is true. F h. Java characters are represented in bytecode. F i. The relational operators cannot be used with character data. F

2 2. The Java Virtual Machine (JVM) accepts data generated by the java compiler. 3. The smallest addressable unit of memory is called a byte. 4. Case values in switch statements can be of type int or type char. 5. The one type of primitive variable that cannot be casted is boolean. 6. Convert 36 to binary showing 8 bits 00100100 7. What is the decimal value of: 01101001 105 8. Show -73 as a sixteen bit binary in two s complement format 0000000001001001 = 73 1111111110110110 flipped 1111111110110111 one is added

3 9. Calculate the following assuming java rules apply with respect to typing 3 (4%3) + (3/4) + (1/2.0) = 3-1+0+.5 = 2.5 10. Evaluate the following assuming java rules apply with respect to typing ((5%3) > (5/3)) = true 11. Place parentheses according to the Java precedence for operators. Then evaluate as Java would. 1+2+3+4/5 = 6 12. Find the value of num at the end of the following segment: int newnum, num = 8; newnum = --num; num = newnum++; 7 13. What is the value of:!((t&&f) (F&&T)) = true

4 14. What does the segment below print to the screen? int firstint = 30, secondint=20; if ((firstint > 40 ) (secondint <30)) { System.out.print("It is a true "); } else { System.out.print("It is a false "); } System.out.println("statement."); It is a true statement Extra Scratch Paper

5 Programs: 21 points each pick two out of three to submit 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. GreatestLeast. Write a program that asks the user to enter four integers. The program will then write out the greatest and the least of these numbers as integers, and the average of the four numbers as a floating point number. Output would like this with the proper values inserted: Greatest Number: Least Number: Average of all the numbers: 2. InchConversion Write a program that prompts for the number of inches a quarterback threw for in his previous game. Convert that into yards, feet, and inches, and prints the results. For instance, The output for 197 inches would be: Yards: 5 Feet: 1 Inches: 5 3. GAS Al's Last Chance Gas station sits on Route 190 on the edge of Death Valley. There is no other gas station for 200 miles. Write a program to help drivers decide if they need gas. The program asks for: The capacity of the gas tank, in gallons. The indication of the gas gauge in percent (full= 100, three quarters full = 75, and so on). The miles per gallon of the car. The program then writes out "Get Gas" or "Safe to Proceed" depending on if the car can cross the 200 miles with the gas remaining in the tank. Tank capacity: 12 Gage reading: 50 Miles per gallon: 30 Get Gas! Use integers for all input and all arithmetic.

6