Review for Test 1 (Chapter 1-5)

Similar documents
Introduction to Programming Using Java (98-388)


HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK

CS313D: ADVANCED PROGRAMMING LANGUAGE

Eng. Mohammed S. Abdualal

What did we talk about last time? Examples switch statements

C-LANGUAGE CURRICULAM

CS-201 Introduction to Programming with Java

Pace University. Fundamental Concepts of CS121 1

Java Notes. 10th ICSE. Saravanan Ganesh

Programming with Java

Chapter 4 Loops. int x = 0; while ( x <= 3 ) { x++; } System.out.println( x );

CS302: Self Check Quiz 2

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

Section 2.2 Your First Program in Java: Printing a Line of Text

VARIABLES AND TYPES CITS1001

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

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

CSI33 Data Structures

Introduction to Java & Fundamental Data Types

Language Reference Manual simplicity

ECE 122. Engineering Problem Solving with Java

Section 2.2 Your First Program in Java: Printing a Line of Text

PROGRAMMING FUNDAMENTALS

Chapter 4: Control structures. Repetition

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Date: Dr. Essam Halim

CS110: PROGRAMMING LANGUAGE I

Flow Control. CSC215 Lecture

Introduction. C provides two styles of flow control:

SECTION II: LANGUAGE BASICS

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

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

Chapter 6 Primitive types

Computational Expression

CS 61C: Great Ideas in Computer Architecture Introduction to C

RTL Reference 1. JVM. 2. Lexical Conventions

Chapter 4: Control structures

Full file at

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

The Arithmetic Operators

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

The Math Class. Using various math class methods. Formatting the values.

Object-Oriented Programming

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

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

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

Values and Variables 1 / 30

Important Java terminology

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

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Chapter 4 Mathematical Functions, Characters, and Strings

CCHAPTER SELECTION STATEMENTS HAPTER 3. Objectives


Getting started with Java

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

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

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Q1. Multiple Choice Questions

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

CS313D: ADVANCED PROGRAMMING LANGUAGE

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

MODULE 02: BASIC COMPUTATION IN JAVA

Introduction to Computer Science Midterm 3 Fall, Points

Chapter 1: Introduction to Computers, Programs, and Java

6.096 Introduction to C++ January (IAP) 2009

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Assignment: 1. (Unit-1 Flowchart and Algorithm)

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

CS111: PROGRAMMING LANGUAGE II

1007 Imperative Programming Part II

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

Fall 2017 CISC124 9/16/2017

Following is the general form of a typical decision making structure found in most of the programming languages:

CHAPTER 7 ARRAYS: SETS OF SIMILAR DATA ITEMS

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

JAVA OPERATORS GENERAL

Unit 2: Java in the small. Prepared by: Dr. Abdallah Mohamed, AOU-KW

Repetition Structures

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

Operators and Expressions

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

Computer System and programming in C

Operators. Java operators are classified into three categories:

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

Index COPYRIGHTED MATERIAL

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

3. Java - Language Constructs I

Chapter 2: Using Data

Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition

Zheng-Liang Lu Java Programming 45 / 79

Unit 1: Introduction to C Language. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune

Simple Java Reference

Language Reference Manual

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Unit 2: Java in the small

Transcription:

Review for Test 1 (Chapter 1-5) 1. Introduction to Computers, Programs, and Java a) What is a computer? b) What is a computer program? c) A bit is a binary digit 0 or 1. A byte is a sequence of 8 bits. d) Programming language Machine language Assembly language High-level language: source program e) What is a compiler? f) What is the operation system (OS)? g) Java Java source code file must end with.java extension Every class is compiled into a separate bytecode file that has the same name as the class and ends with the.class extension To compile a Java course code file from the command line, use the javac command To run a Java class from the command line, use the java command Every Java program is a set of class definitions To run a Java program, the program must have a main method Java source programs are case sensitive. h) Programming errors Syntax errors Runtime errors Logic errors 2. Elementary Programming a) Identifiers b) Variables c) import statements d) assignment operator = e) constant f) Java primitive data types g) Numeric operations: +, -, *, /, % h) Augmented assignment operators: +=, -=, *=, /=, %= i) Increment operator (++) and the decrement operator (--) j) Type casting

Exercises: 2.1 Write a statement to declare a variable named x of the double type with an initial value 4.5. 2.2 Write a statement to declare a constant named MAX of the int type with value 45. 2.3 15 % 2 = 2.4 Write an expression that returns an integer from casting 1.7. 2.5 (int)(24.768 * 100) / 100.0 = 2.6 (int)(24.768 * 100) / 100 = 2.7 Use an augmented assignment operator to write a statement to add 5 into variable x. 2.8 Write an expression for 2.5 5.4. 2.9 What is the data type for a variable that stores the value 2.5F or 2.5f? 2.10 What is a possible data type for a variable that stores the value 32768? 2.11 What is a possible data type for a variable that stores the value 2147L?

3. Selections a) boolean type b) Relational operators: <. <=, ==,!=, >, >= c) selection statements one way if statements two way if-else statements nested if statements multi-way if-else statements switch statements d) Boolean expression e) Boolean operators: &&,,!, ^ f) Conditional expression:? : g) Operator precedence Exercises: 3.1 Write an expression that returns a random integers between 0 and 9, inclusive. 3.2 What is (int)math.random() * 10? 3.3 Assume age = 16; ticketprice = age >= 16? 20 : 10; What is ticketprice? 3.4 Assume x is an integer. Write a simple expression that returns true if x is even or false if x is odd. 3.5 What is true ^ false? 4. Mathematical Functions, Characters, and Strings a) Methods type Instance methods Static methods

b) Mathematical methods random pow etc. c) char data type and methods isdigit isuppercase etc. d) escape sequence and escape characters e) String data type and methods length concat subsring equals etc. f) formatting outputs: printf Exercises: 4.1 Write an expression that returns the sine of angle degree 36.5 using Math.sin and Math.toRadians. 4.2 What is Math.round(5.4)? 4.3 What is a literal for character A? 4.4 What is the string literal that consists of a single character A? 4.5 Write an expression that tests whether a character ch is a digit. 4.6 Write an expression that returns the first character in string s.

4.7 What is the output of System.out.print("ABCD".substring(2))? 4.8 What is the output of System.out.print("ABCD".indexOf("BC"))? 4.9 What is the output of System.out.printf("%-6.2f%-6.2f", 3.503, 4.355)? 5. Loops a) Loop statements while do-while for b) infinite loop c) sentinel value d) break and continue keyword Exercises: 5.1 How many times is the following loop executed? int count = 1; while (count < 5) { count += 3; 5.2 How many times is the following loop executed? int count = 1; do { count += 3; while (count < 5); 5.3 How many times is the following loop executed? for (int count = 1; count < 5; count += 3) { // Execute the body 5.4 What is count after the loop is finished? int count = 1; do { count += 3;

while (count < 5); 5.5 What is the output of the following code? for (int i = 1; i < 10; i += 2) { System.out.printf("%1d", i); 5.6 What is the output of the following code? int x = 85; for (int i = 2; i < x; i++) { if (x % i == 0) { System.out.print(i); break; 5.7 What is the output of the following code? int x = 85; for (int i = 2; i < x; i++) { if (x % i == 0) { System.out.print(i + " "); continue;