Peer Instruction 1. Elementary Programming

Similar documents
Programming with Java

Computational Expression

Chapter 2: Data and Expressions

5) (4 points) What is the value of the boolean variable equals after the following statement?

ECE 122 Engineering Problem Solving with Java

Data Conversion & Scanner Class

Introduction to Programming Using Java (98-388)

Getting started with Java

Computational Expression

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

Full file at

COMP 110/L Lecture 4. Kyle Dewey

Chapter 2: Data and Expressions

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CS110: PROGRAMMING LANGUAGE I

Entry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes

Chapter 2: Basic Elements of Java

Input. Scanner keyboard = new Scanner(System.in); String name;

Gaddis: Starting Out with Java: From Control Structures through Objects, 6/e

Java Console Input/Output The Basics. CGS 3416 Spring 2018

Starting Out with Java: From Control Structures through Data Structures 3e (Gaddis and Muganda) Chapter 2 Java Fundamentals

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

AP Computer Science Unit 1. Writing Programs Using BlueJ

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

4. If the following Java statements are executed, what will be displayed?

loop++; System.out.println(loop);

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

Full file at

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

boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while

printf( Please enter another number: ); scanf( %d, &num2);

Hello World. n Variables store information. n You can think of them like boxes. n They hold values. n The value of a variable is its current contents

Computer Science 145 Midterm 1 Fall 2016

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Primitive Data Types: Intro

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Elementary Programming

Chapter 2 Elementary Programming

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

Chapter 02: Using Data

Reserved Words and Identifiers

VARIABLES AND TYPES CITS1001

AP Computer Science A

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

AP Computer Science Unit 1. Programs

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

CIS133J. Working with Numbers in Java

CS 302: Introduction to Programming

Basic Programming Elements

Arithmetic and IO. 25 August 2017

Java Console Input/Output The Basics

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

CS313D: ADVANCED PROGRAMMING LANGUAGE

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

Using Java Classes Fall 2018 Margaret Reid-Miller

Fundamentals of Programming Data Types & Methods

CEN 414 Java Programming

Chapter 2: Using Data

Variables and Assignments CSC 121 Spring 2017 Howard Rosenthal

Define a method vs. calling a method. Chapter Goals. Contents 1/21/13

Full file at

What did we talk about last time? Examples switch statements

Java Foundations Certified Junior Associate

PRIMITIVE VARIABLES. CS302 Introduction to Programming University of Wisconsin Madison Lecture 3. By Matthew Bernstein

ITI1120 Introduction to Computing I Exercise Workbook Fall 2012

Variables and Assignments CSC 121 Fall 2015 Howard Rosenthal

Numerical Data. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Data Types. 1 You cannot change the type of the variable after declaration. Zheng-Liang Lu Java Programming 52 / 87

Object-Based Programming. Programming with Objects

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Introduction to Java Unit 1. Using BlueJ to Write Programs

Chapter. Let's explore some other fundamental programming concepts

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

Declaration and Memory

Chapter 4 Classes in the Java Class Libraries

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

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

Practice Midterm 1 Answer Key

Computer Programming, I. Laboratory Manual. Experiment #4. Mathematical Functions & Characters

Values and Variables 1 / 30

ing execution. That way, new results can be computed each time the Class The Scanner

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

Chapter 2 ELEMENTARY PROGRAMMING

c) And last but not least, there are javadoc comments. See Weiss.

Homework #3 CS2255 Fall 2012

Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs

CSc Introduction to Computing

Lecture Set 2: Starting Java

Motivations. Chapter 2: Elementary Programming 8/24/18. Introducing Programming with an Example. Trace a Program Execution. Trace a Program Execution

Data Types and the while Statement

COMP 110 Introduction to Programming. What did we discuss?

Data Types & Variables

Lecture Set 2: Starting Java

AP Computer Science Unit 1. Writing Programs Using BlueJ

First Java Program - Output to the Screen

COMP 202 Java in one week

CS61B Lecture #14: Integers. Last modified: Wed Sep 27 15:44: CS61B: Lecture #14 1

LECTURE 3 C++ Basics Part 2

Transcription:

Peer Instruction 1 Elementary Programming 0

Which of the following variable declarations will not compile? Please select the single correct answer. A. int i = 778899; B. double x = 5.43212345; C. char c = & ; D. short s0,s1=567,s3; E. All declarations are correct! cs163/164: Peer 1 - Elementary Programming - Fall Semester 2016 Question - 1 Correct answer is C, needs a character literal with single quotes instead of a string. 1

Which of the statements below that declare and initialize an integer will not compile? Please select the single correct answer. A. short s0 = 7809; B. int i1 = 345.678; C. double d0 = 3357872; D. double d1 = 35.7893993; E. All of the above cs163/164: Peer 1 - Elementary Programming - Fall Semester 2016 Question - 2 Correct answer is B, trying to put a double into an integer without type casting. 2

Which of the following lists of variable names are legal identifiers in Java? Please select the single correct answer. A. file3, String, int, _name13 B. 3file, name3, $real0 C. file3, string, #hashtag, double D. file3, string, int2, _name1 cs163/164: Peer 1 - Elementary Programming - Fall Semester 2016 Question - 3 Correct answer is D, no illegal characters, no numbers, no reserved words, no classes, underscore okay. 3

What is the difference between the primitive types shown below? byte, short, int, long A. No difference except for the names! B. Some represent integers, others real numbers C. Each type has a different size in memory D. Some types are signed, some are unsigned cs163/164: Peer 1 - Elementary Programming - Fall Semester 2016 Question - 4 Correct answer is C, 8-bit, 16-bit, 32-bit, and 64-bit. 4

What will the code below assign to the value of the integer variable? int myinteger = 9/4 + 44/11 + 11%3 + (6/4); A. 9 B. 9.75 C. 10 D. 10.25 cs163/164: Peer 1 - Elementary Programming - Fall Semester 2016 Question - 5 Correct answer is A, explain integer math and modulo. 5

What will the code below assign to the value of the integer variable? int myinteger = 6 * 2 / 3 + 5 * 6 15 / 5; A. 4 B. 16 C. 31 D. 47 cs163/164: Peer 1 - Elementary Programming - Fall Semester 2016 Question - 6 Correct answer is C, explain order of operations. 6

Which of the statements below does not increment (and save) the declared integer? int myinteger = 0; A. myinteger++; B. ++myinteger; C. myinteger + 1; D. myinteger += 1; E. myinteger = myinteger + 1; cs163/164: Peer 1 - Elementary Programming - Fall Semester 2016 Question - 7 Correct answer is C, adds one for evaluation but does not change the value (and will not compile). 7

Which of the following statements will not compile because of an incorrect type cast? Select the one correct answer. A. int i0 = (char) $ ; B. int i1 = (int) 76.1234; C. int i2 = (short) 34; D. int i3 = (float) 3213; E. All of the above cs163/164: Peer 1 - Elementary Programming - Fall Semester 2016 Question - 8 Correct answer is D, once you type cast to float you cannot assign to integer. 8

Which of the statements below successfully prints the value of the variable? double mydouble = 1.2345; A. System.out.println("Value = " + mydouble); B. System.out.println("Value = ", mydouble); C. System.out.println("Value = " mydouble); D. System.out.println("Value = mydouble"); cs163/164: Peer 1 - Elementary Programming - Fall Semester 2016 Question - 9 Correct answer is A, need to concatenate the string and value using + operator. 9

What will the code shown below print to the console? System.out.printf("%.4f\n", 52.978353490); A. 52.978353490 B. 52.9783 C. 52.9784 D..9783 cs163/164: Peer 1 - Elementary Programming - Fall Semester 2016 Question - 10 Correct answer is C, does not touch left of decimal point, rounds to specified number of digits. 10

Which line successfully creates a Scanner object to read from the keyboard? Please select the single correct answer. A. Scanner scan; B. Scanner scan = new Scanner(); C. Scanner scan = new Scanner("keyboard"); D. Scanner scan = new Scanner(System); E. Scanner scan = new Scanner(System.in); cs163/164: Peer 1 - Elementary Programming - Fall Semester 2016 Question - 11 Correct answer is E, System.in is the input stream from the keyboard, C will compile! Bonus: Why does sending a String to the constructor work? Answer: It makes a parser for the String. 11

Which line successfully reads an integer from the keyboard into the declared variable? int myinteger; Scanner scan = new Scanner (System.in); A. myinteger = scan.next(); B. myinteger = scan.nextint; C. myinteger = scan.nextint(); D. myinteger = nextint(); cs163/164: Peer 1 - Elementary Programming - Fall Semester 2016 Question - 12 Correct answer is C, must use the object to call the method, parentheses required for method calls. 12