AP Computer Science A Unit 2. Exercises

Size: px
Start display at page:

Download "AP Computer Science A Unit 2. Exercises"

Transcription

1 AP Computer Science A Unit 2. Exercises A common standard is 24-bit color where 8 bits are used to represent the amount of red light, 8 bits for green light, and 8 bits for blue light. It is the combination of these three colors that generates every other color you see on a monitor. 1. How many different levels of red can be represented using 8 bits? 2. How many different colors can be represented using 24 bits? Y2K refers to a computer problem from the previous century. In the early days of computers, memory (whether for storage or running a program) was very expensive. So, when recording dates, only the last two digits were saved. For example, the year 1985 would be saved as 85. This worked well enough for most programs at first but with the approach of the year 2000, it needed to be fixed; otherwise the year 2000 would be indistinguishable from the year 1900 (as both would be saved as 00). 3. How many bits are necessary to save a number from 0 to 99? 4. How many bits are necessary to save a number from 0 to 9999? 5. An Arduino Uno microcontroller can detect a voltage between 0 and 5 volts. How many bits does it use to represent the voltage if 1023 indicates 5 volts and 0 indicates 0 volts? Translate each binary number into a base ten number. 6) ) ) ) ) ) Translate each hexadecimal number into a base ten number 12) ) 2F 16 14) 5D 16 15) A ) )

2 Translate each number into a base 10 number. If a number is incorrectly represented, and therefore cannot be translated, write INVALID. 18) ) ) ) ) ) 55 6 Translate each base ten integer into a binary number. 24) 67 25) ) 8 27) 12 28) 50 29) 88 Translate each base ten number into a hexadecimal number. 30) 30 31) ) 8 33) 64 34) 54 35) 75 36) Convert this integer from base 10 to base ) Convert this integer from base 10 to base ) Convert this integer from base 10 to base ) Convert this integer from base 10 to base

3 Any binary number can be easily converted to hexadecimal, and vice versa. Since 4 bits can represent a value between 0 and 15, each group of 4 bits can converted to the corresponding hex number. For example = D4 because 1101 = D and 0100 = 4 40) This is why hex numbers are so common. For example, going back to the problems at the beginning of this packet, which is the easier way to specify a color? a) B16FCA b) Translate each binary number into a hexadecimal number. 41) ) ) ) ) ) Translate each hexadecimal number into a binary. 47) FE 16 48) ) ) 4F ) A ) B03 16 Run the following program in BlueJ to answer questions 53 to 56. import javax.swing.jcolorchooser; import java.awt.color; public class MyColorChooser { public static void main(string[] args) { Color c1 = Color.ORANGE; Color c2 = JColorChooser.showDialog( null,"pick a Color", c1 ); System.out.println( c2.tostring() ); 53. Click on the RGB tab and set Red to 255, Green to 255, Blue to 0, and Alpha to 255. What background color of the sample text?. 3

4 54. Change the color code to 00FF00. What is the background color of the sample text? Why? 55. If the color code is , what is the background color of the text? 56. If color1 is CC0000 and color2 is , which color is darker? Try to figure this out first then check by entering those numbers. 57. Java code is saved in a text file that has a.class extension. True False 58. To run Java byte code on a particular computer, you must install a java compiler. True False 59. The JVM detects run-time errors. True False 60. The JVM detects logic errors. True False 61. The Java compiler translates text into Byte code. True False 62. The JVM translates byte code into the machine language of the particular device it is installed on. True False 63. A bit consists of 8 bytes. True False 64. The same Java class files can be run on a variety of computers (e.g. those running Windows, Linux, etc.) True False 65) Is the following binary number even or odd? There is a way to figure this out without converting it to a base 10 integer. 66) Let s say you ve written a program that looks something like this: public class Light{ public static void main(string[] args) { // some great code and I say, me the code. Which file(s) should you send me? a) Light.java b) Light.ctxt c) Light.class d) All of the above files e) Any of the first three files. 4

5 67) ASCII (American Standard Code for Information Interchange), started in the 1960 s, was a very common 7 bit encoding scheme for letters, numbers, etc. What was the total number of characters that it could represent? Numbers 65 to 90 represented the uppercase letters A to Z. Numbers 97 to 112 represented the lowercase letters a to z. Convert 65 (base ten) to binary Convert 97 (base ten) to binary How many bits have to be changed to convert a lowercase letter to an uppercase letter (or vice versa)? 68) Numeric literals can be represented in binary form by putting 0b or 0B in front (that s a zero, not an O). However, the value of an int is still displayed in base 10. What is displayed? 69) Putting 0x, or 0X, before a numeric literal means that it is a hexadecimal value. What is displayed? int x = 0b11; int y = 0b11; int c = x + y; System.out.println( c ); int x = 0xF; int y = 0x2; int c = x + y; System.out.println( c ); 70) What is displayed? int x = 0b1110; int y = 0x12; int c = x + y; System.out.println( c ); 71) What is displayed? int num1 = 0b0010; int num2 = 0x10; int result = num1 * num2; System.out.println( result ); Note: Curly brackets { are optional if there is only one statement associated with the if (or ) statement.) 72. If the user enters 82, what is displayed? 73. If the user enters 2, what is displayed? Scanner get = new Scanner(System.in); System.out.print( "Enter a number: " ); int x = get.nextint(); if ( x < 7 ) { System.out.print( "A" ); System.out.print( "B" ); System.out.print( "C" ); 5

6 74. If the user enters 10, what is displayed? 75. If the user enters 12, what is displayed? 76. Are the curly braces required in this code? 77. If the user enters 10, what is displayed? 78. If the user enters 4, what is displayed? 79. If the user enters 2, what is displayed? 80. If x has an initial value of 33, what is its final 81. If x has an initial value of 62, what is its final Scanner get = new Scanner(System.in); System.out.print( "Enter a number: " ); int x = get.nextint(); System.out.print( "AA" ); if ( 11 >= x ) { System.out.print( "BB" ); System.out.print( "CC" ); Scanner get = new Scanner(System.in); System.out.print( "Enter a number: " ); int x = get.nextint(); if ( x!= 10 ) x = x + 3; if ( x > 7 ) x = x + 12; x = x - 1; System.out.println( x ); // x is declared and assigned a value if ( x > 30 && x <= 50 ) x = x + 10; x = x - 4; if ( x < 40 && x > 60 ) x = x + 2; 82. If x has a value of -5 and y has a value of 63, what is displayed? 83. If x has a value of 47 and y has a value of 47, what is displayed? 84. Select the TRUE statement. a) H is never printed. b) H is always printed. c) H is only printed sometimes. // x and y are declared and initialized if ( x > 30 y >= 60 ) System.out.print( "G" ); if ( x < 100 x > 40 ) System.out.print( "H" ); if ( y < 10 y > 50 ) System.out.print( "K" ); 6

7 85. If y has an initial value of 12, what is displayed? 86. If y has an initial value of 26, what is displayed? 87. If y has an initial value of 7, what is displayed? 88. The code to the right does not compile. The is highlighted and the error message is: without if Why? 89. Given that the above error is fixed by the addition of two characters, what will be displayed if the user enters 12? 90. If x has an initial value of -8, what is its final 91. If x has an initial value of 9, what is its final 92. If x has an initial value of 15, what is its final 93. If x has an initial value of 22, what is its final 94. If x has a final value of 6, what was its initial Scanner x = new Scanner( System.in ); System.out.println( "Number?" ); int y = x.nextint(); if ( y > 10 ) y += 10; if ( y > 20 ) y++; System.out.println( y ); Scanner read = new Scanner( System.in ); System.out.println( "Number?" ); int a = read.nextint(); if ( a > 10 && a < 20 ) a = 2 * a; System.out.println( a ); a--; System.out.println( a ); // x is declared and assigned a value if ( x > 10 x < 20 ) x = x + 2; if ( x < 10 x > 20 ) x = x + 3; // x is declared and assigned a value if ( x > 10 && x < 20 ) x = x + 2; if ( x < 10 && x > 20 ) x = x + 3; if ( x > 10 && x > 20 ) x = x + 10; 95. If the user enters "38", what is displayed? 96. If the user enters -4, what is displayed? 97. If the user enters 99, what is displayed? Scanner read; read = new Scanner(System.in); System.out.print( "Enter a number: " ); int num = read.nextint(); if ( num < 13) { System.out.println( "ZZ" ); if ( num < 20) { System.out.println( "YY" ); if ( num < 40 ) { System.out.println( "XX" ); System.out.println( "WW" ); 7

8 98. If k has an initial value of 13, what is its final 99. If k has an initial value of 22, what is its final 100. If k has an initial value of 4, what is its final // k is declared and assigned a value if ( k < 5 ) k += 2; if ( k < 10 ) k += 5; if ( k < 20 ) k += 6; 101. If k has an initial value of 10, what is its final 102. If k has an initial value of 30, what is its final // k is declared and assigned a value if ( k < 11 ) k += 4; if ( k < 40 ) k++; 103. Lines 7 and 8 can be deleted without changing how the code runs. TRUE FALSE if ( k > 11 ) k = k - 2; if ( k > 22 ) k -= 4; 104. If x has an initial value of 8, what is its final 105. If x has an initial value of 11, what is its final 106. If x has an initial value of 19, what is its final // x is declared and assigned a value if ( x > 10 ) x = x + 2; if ( x < 5 ) x++; if ( x <= 20 ) x = 2*x; if ( x > 5 ) x++; 107. short is an integer data type that is two bytes long. char is also two bytes long but its values are interpreted as characters. The same bits are stored in both variables. What is displayed? short a = 0b ; char b = 0b ; System.out.println( a ); System.out.println( b ); You will not be tested on shorts or bytes. 8

9 if ( x > 5 ){ if ( x < 10 ) System.out.println("YES"); if ( x > 5 && x < 10 ) System.out.println("YES"); 108. Do the above two code snippets produce the same results? If they do not, what value of x will cause different results? if ( x > 5 ) System.out.println("NO"); if ( x < 2 ) System.out.println("NO"); System.out.println("MAYBE"); if ( x < 2 x > 5 ) System.out.println("NO"); System.out.println("MAYBE"); 109. Do the above two code snippets produce the same results? If they do not, what value of x will cause different results? if ( x > 20 ) { if ( x < 50 ) System.out.println("ONE"); System.out.println("TWO"); if ( x > 20 && x < 50 ) System.out.println("ONE"); System.out.println("TWO"); 110. Do the above two code snippets produce the same results? If they do not, what value of x will cause different results? 9

Introduction to Computer Science Unit 2. Exercises

Introduction to Computer Science Unit 2. Exercises Introduction to Computer Science Unit 2. Exercises Note: Curly brackets { are optional if there is only one statement associated with the if (or ) statement. 1. If the user enters 82, what is 2. If the

More information

Computational Expression

Computational Expression Computational Expression Variables, Primitive Data Types, Expressions Janyl Jumadinova 28-30 January, 2019 Janyl Jumadinova Computational Expression 28-30 January, 2019 1 / 17 Variables Variable is a name

More information

Mr. Monroe s Guide to Mastering Java Syntax

Mr. Monroe s Guide to Mastering Java Syntax Mr. Monroe s Guide to Mastering Java Syntax Getting Started with Java 1. Download and install the official JDK (Java Development Kit). 2. Download an IDE (Integrated Development Environment), like BlueJ.

More information

Introduction to Computer Science Unit 2. Notes

Introduction to Computer Science Unit 2. Notes Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and

More information

AP Computer Science Unit 1. Programs

AP Computer Science Unit 1. Programs AP Computer Science Unit 1. Programs Open DrJava. Under the File menu click on New Java Class and the window to the right should appear. Fill in the information as shown and click OK. This code is generated

More information

AP CS Unit 3: Control Structures Notes

AP CS Unit 3: Control Structures Notes AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts

More information

Midterm Examination (MTA)

Midterm Examination (MTA) M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and

More information

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

Section 003 Fall CS 170 Exam 1. Name (print): Instructions: CS 170 Exam 1 Section 003 Fall 2012 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics WIT COMP1000 Java Basics Java Origins Java was developed by James Gosling at Sun Microsystems in the early 1990s It was derived largely from the C++ programming language with several enhancements Java

More information

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 Question One: Choose the correct answer and write it on the external answer booklet. 1. Java is. a. case

More information

St. Edmund Preparatory High School Brooklyn, NY

St. Edmund Preparatory High School Brooklyn, NY AP Computer Science Mr. A. Pinnavaia Summer Assignment St. Edmund Preparatory High School Name: I know it has been about 7 months since you last thought about programming. It s ok. I wouldn t want to think

More information

Important Java terminology

Important Java terminology 1 Important Java terminology The information we manage in a Java program is either represented as primitive data or as objects. Primitive data פרימיטיביים) (נתונים include common, fundamental values as

More information

Programming with Java

Programming with Java Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules

More information

AP Computer Science Unit 1. Writing Programs Using BlueJ

AP Computer Science Unit 1. Writing Programs Using BlueJ AP Computer Science Unit 1. Writing Programs Using BlueJ 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save

More information

Array. Array Declaration:

Array. Array Declaration: Array Arrays are continuous memory locations having fixed size. Where we require storing multiple data elements under single name, there we can use arrays. Arrays are homogenous in nature. It means and

More information

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

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2 CONTENTS: Compilation Data and Expressions COMP 202 More on Chapter 2 Programming Language Levels There are many programming language levels: machine language assembly language high-level language Java,

More information

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

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below. C212 Early Evaluation Exam Mon Feb 10 2014 Name: Please provide brief (common sense) justifications with your answers below. 1. What is the type (and value) of this expression: 5 * (7 + 4 / 2) 2. What

More information

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic BIT 3383 Java Programming Sem 1 Session 2011/12 Chapter 2 JAVA basic Objective: After this lesson, you should be able to: declare, initialize and use variables according to Java programming language guidelines

More information

AP Computer Science Unit 1. Writing Programs Using BlueJ

AP Computer Science Unit 1. Writing Programs Using BlueJ AP Computer Science Unit 1. Writing Programs Using BlueJ 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save

More information

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

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

More information

PROGRAMMING FUNDAMENTALS

PROGRAMMING FUNDAMENTALS PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write

More information

Introduction to Java & Fundamental Data Types

Introduction to Java & Fundamental Data Types Introduction to Java & Fundamental Data Types LECTURER: ATHENA TOUMBOURI How to Create a New Java Project in Eclipse Eclipse is one of the most popular development environments for Java, as it contains

More information

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

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Getting started with Java

Getting started with Java Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving

More information

CS Week 5. Jim Williams, PhD

CS Week 5. Jim Williams, PhD CS 200 - Week 5 Jim Williams, PhD The Study Cycle Check Am I using study methods that are effective? Do I understand the material enough to teach it to others? http://students.lsu.edu/academicsuccess/studying/strategies/tests/studying

More information

Java Programming Language. 0 A history

Java Programming Language. 0 A history Java Programming Language 0 A history How java works What you ll do in Java JVM API Java Features 0Platform Independence. 0Object Oriented. 0Compiler/Interpreter 0 Good Performance 0Robust. 0Security 0

More information

Java Bytecode (binary file)

Java Bytecode (binary file) Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.

More information

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks: كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this

More information

Introduction to Computer Science Unit 2. Notes

Introduction to Computer Science Unit 2. Notes Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and

More information

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

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled Interpreted vs Compiled Python 1 Java Interpreted Easy to run and test Quicker prototyping Program runs slower Compiled Execution time faster Virtual Machine compiled code portable Java Compile > javac

More information

Chapter 2: Basic Elements of Java

Chapter 2: Basic Elements of Java Chapter 2: Basic Elements of Java TRUE/FALSE 1. The pair of characters // is used for single line comments. ANS: T PTS: 1 REF: 29 2. The == characters are a special symbol in Java. ANS: T PTS: 1 REF: 30

More information

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

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine

More information

Operators in java Operator operands.

Operators in java Operator operands. Operators in java Operator in java is a symbol that is used to perform operations and the objects of operation are referred as operands. There are many types of operators in java such as unary operator,

More information

B.V. Patel Institute of BMC & IT, UTU 2014

B.V. Patel Institute of BMC & IT, UTU 2014 BCA 3 rd Semester 030010301 - Java Programming Unit-1(Java Platform and Programming Elements) Q-1 Answer the following question in short. [1 Mark each] 1. Who is known as creator of JAVA? 2. Why do we

More information

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

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural

More information

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

Following is the general form of a typical decision making structure found in most of the programming languages: Decision Making Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed if the condition is determined

More information

AP COMPUTER SCIENCE A

AP COMPUTER SCIENCE A AP COMPUTER SCIENCE A CONTROL FLOW Aug 28 2017 Week 2 http://apcs.cold.rocks 1 More operators! not!= not equals to % remainder! Goes ahead of boolean!= is used just like == % is used just like / http://apcs.cold.rocks

More information

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural

More information

Introduction to Java Unit 1. Using BlueJ to Write Programs

Introduction to Java Unit 1. Using BlueJ to Write Programs Introduction to Java Unit 1. Using BlueJ to Write Programs 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save

More information

Software and Programming 1

Software and Programming 1 Software and Programming 1 Lab 1: Introduction, HelloWorld Program and use of the Debugger 17 January 2019 SP1-Lab1-2018-19.pptx Tobi Brodie (tobi@dcs.bbk.ac.uk) 1 Module Information Lectures: Afternoon

More information

Oct Decision Structures cont d

Oct Decision Structures cont d Oct. 29 - Decision Structures cont d Programming Style and the if Statement Even though an if statement usually spans more than one line, it is really one statement. For instance, the following if statements

More information

What did we talk about last time? Examples switch statements

What did we talk about last time? Examples switch statements Week 4 - Friday What did we talk about last time? Examples switch statements History of computers Hardware Software development Basic Java syntax Output with System.out.print() Mechanical Calculation

More information

CS-201 Introduction to Programming with Java

CS-201 Introduction to Programming with Java CS-201 Introduction to Programming with Java California State University, Los Angeles Computer Science Department Lecture V: Mathematical Functions, Characters, and Strings Introduction How would you estimate

More information

Chapter 3 Intro to Java

Chapter 3 Intro to Java Chapter 3 Intro to Java Introducing Java Barrett Computer Science Designing Technology Solutions 1 2 Key Terminology - OS Operating System 3 Why Program in Java? Java is an Object Oriented Programming

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical

More information

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

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch

More information

COMP2121: Microprocessors and Interfacing. Number Systems

COMP2121: Microprocessors and Interfacing. Number Systems COMP2121: Microprocessors and Interfacing Number Systems http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 2, 2017 1 1 Overview Positional notation Decimal, hexadecimal, octal and binary Converting

More information

The Big Idea: Background: About Serial

The Big Idea: Background: About Serial Lesson 6 Lesson 6: Serial Serial Input Input The Big Idea: Information coming into an Arduino sketch is called input. This lesson focuses on text in the form of characters that come from the user via the

More information

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

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

More information

Chapter 02: Using Data

Chapter 02: Using Data True / False 1. A variable can hold more than one value at a time. ANSWER: False REFERENCES: 54 2. The int data type is the most commonly used integer type. ANSWER: True REFERENCES: 64 3. Multiplication,

More information

Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1

Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1 Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1 Motivation In the programs we have written thus far, statements are executed one after the other, in the order in which they appear. Programs often

More information

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution Ch 5 Arrays Multiple Choice Test 01. An array is a ** (A) data structure with one, or more, elements of the same type. (B) data structure with LIFO access. (C) data structure, which allows transfer between

More information

Introduction to Java Applications; Input/Output and Operators

Introduction to Java Applications; Input/Output and Operators www.thestudycampus.com Introduction to Java Applications; Input/Output and Operators 2.1 Introduction 2.2 Your First Program in Java: Printing a Line of Text 2.3 Modifying Your First Java Program 2.4 Displaying

More information

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader? CIS 3022 Prog for CIS Majors I October 4, 2007 Exam I Print Your Name Your Section # Total Score Your work is to be done individually. The exam is worth 104 points (four points of extra credit are available

More information

CHAPTER 5 VARIABLES AND OTHER BASIC ELEMENTS IN JAVA PROGRAMS

CHAPTER 5 VARIABLES AND OTHER BASIC ELEMENTS IN JAVA PROGRAMS These are sample pages from Kari Laitinen s book "A Natural Introduction to Computer Programming with Java". For more information, please visit http://www.naturalprogramming.com/javabook.html CHAPTER 5

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 1 Section 000 Spring 2014 Name (print):. Instructions Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

JAVA Programming Fundamentals

JAVA Programming Fundamentals Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

More information

CS11 Java. Fall Lecture 1

CS11 Java. Fall Lecture 1 CS11 Java Fall 2006-2007 Lecture 1 Welcome! 8 Lectures Slides posted on CS11 website http://www.cs.caltech.edu/courses/cs11 7-8 Lab Assignments Made available on Mondays Due one week later Monday, 12 noon

More information

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. Today! Build HelloWorld yourself in BlueJ and Eclipse. Look at all the Java keywords. Primitive Types. HelloWorld in BlueJ 1. Find BlueJ in the start menu, but start the Select VM program instead (you

More information

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2 Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2 Instructor: Rob Bergen Applied Computer Science University of Winnipeg Announcements Website is up

More information

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I AL GHURAIR UNIVERSITY College of Computing CSC 209 JAVA I week 2- Arithmetic and Decision Making: Equality and Relational Operators Objectives: To use arithmetic operators. The precedence of arithmetic

More information

4 Programming Fundamentals. Introduction to Programming 1 1

4 Programming Fundamentals. Introduction to Programming 1 1 4 Programming Fundamentals Introduction to Programming 1 1 Objectives At the end of the lesson, the student should be able to: Identify the basic parts of a Java program Differentiate among Java literals,

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 05 / 31 / 2017 Instructor: Michael Eckmann Today s Topics Questions / Comments? recap and some more details about variables, and if / else statements do lab work

More information

Datatypes, Variables, and Operations

Datatypes, Variables, and Operations Datatypes, Variables, and Operations 1 Primitive Type Classification 2 Numerical Data Types Name Range Storage Size byte 2 7 to 2 7 1 (-128 to 127) 8-bit signed short 2 15 to 2 15 1 (-32768 to 32767) 16-bit

More information

Repe$$on CSC 121 Fall 2015 Howard Rosenthal

Repe$$on CSC 121 Fall 2015 Howard Rosenthal Repe$$on CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while

More information

Zheng-Liang Lu Java Programming 45 / 79

Zheng-Liang Lu Java Programming 45 / 79 1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius

More information

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 123 Computer Creativity Introduction to Java Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) Introduce Java, a general-purpose programming language,

More information

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

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value Lecture Notes 1. Comments a. /* */ b. // 2. Program Structures a. public class ComputeArea { public static void main(string[ ] args) { // input radius // compute area algorithm // output area Actions to

More information

CMSC131. Introduction to your Introduction to Java. Why Java?

CMSC131. Introduction to your Introduction to Java. Why Java? CMSC131 Introduction to your Introduction to Java Why Java? It s a popular language in both industry and introductory programming courses. It makes use of programming structures and techniques that can

More information

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

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process Entry Point of Execution: the main Method Elementary Programming EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG For now, all your programming exercises will

More information

APCS Semester #1 Final Exam Practice Problems

APCS Semester #1 Final Exam Practice Problems Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester

More information

Welcome to the Using Objects lab!

Welcome to the Using Objects lab! Welcome to the Using Objects lab! Learning Outcomes By the end of this lab: 1. Be able to define chapter 3 terms. 2. Describe reference variables and compare with primitive data type variables. 3. Draw

More information

Computer Programming, I. Laboratory Manual. Final Exam Solution

Computer Programming, I. Laboratory Manual. Final Exam Solution Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Final Exam Solution

More information

Fall 2017 CISC124 9/16/2017

Fall 2017 CISC124 9/16/2017 CISC124 Labs start this week in JEFF 155: Meet your TA. Check out the course web site, if you have not already done so. Watch lecture videos if you need to review anything we have already done. Problems

More information

At its simplest, a computer is a collection of wires, transistors and electrical components that are connected in a specific way When you send

At its simplest, a computer is a collection of wires, transistors and electrical components that are connected in a specific way When you send What is a computer? At its simplest, a computer is a collection of wires, transistors and electrical components that are connected in a specific way When you send certain sequences of voltages down the

More information

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:

Mid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks: Mid Term Exam 1 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Student Name: Total Marks: 50 Obtained Marks: Instructions: Do not open this exam booklet until you

More information

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.

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. Introduction to JAVA JAVA is a programming language which is used in Android App Development. It is class based and object oriented programming whose syntax is influenced by C++. The primary goals of JAVA

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #04: Fall 2015 1/20 Office hours Monday, Wednesday: 10:15 am to 12:00 noon Tuesday, Thursday: 2:00 to 3:45 pm Office: Lindley Hall, Room 401C 2/20 Printing

More information

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution

(A) 99 (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution Ch 5 Arrays Multiple Choice 01. An array is a (A) (B) (C) (D) data structure with one, or more, elements of the same type. data structure with LIFO access. data structure, which allows transfer between

More information

Software and Programming 1

Software and Programming 1 Software and Programming 1 Lab 1: Introduction, HelloWorld Program and use of the Debugger 11 January 2018 SP1-Lab1-2017-18.pptx Tobi Brodie (tobi@dcs.bbk.ac.uk) 1 Module Information Lectures: Afternoon

More information

COMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015

COMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015 COMP-202: Foundations of Programming Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015 Announcements Slides will be posted before the class. There might be few

More information

Anatomy of a Java Program: Comments

Anatomy of a Java Program: Comments CS149 Anatomy of a Java Program: Comments Javadoc comments: /** * Application that converts inches to centimeters. * * @author Alvin Chao * @version 01/21/2014 */ Everything between /** and */ ignored

More information

Boolean Expressions. So, for example, here are the results of several simple Boolean expressions:

Boolean Expressions. So, for example, here are the results of several simple Boolean expressions: Boolean Expressions Now we have the ability to read in some information, calculate some formulas and display the information to the user in a nice format. However, the real power of computer programs lies

More information

Fundamentals of Programming Data Types & Methods

Fundamentals of Programming Data Types & Methods Fundamentals of Programming Data Types & Methods By Budditha Hettige Overview Summary (Previous Lesson) Java Data types Default values Variables Input data from keyboard Display results Methods Operators

More information

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring What is your name?: (4 points for writing it on your answer sheet)

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Spring What is your name?: (4 points for writing it on your answer sheet) CS 102 - Introduction to Programming Midterm Exam #1 - Prof. Reed Spring 2008 What is your name?: (4 points for writing it on your answer sheet) There are two sections: I. True/False.....................

More information

Fundamentals of Programming. By Budditha Hettige

Fundamentals of Programming. By Budditha Hettige Fundamentals of Programming By Budditha Hettige Overview Exercises (Previous Lesson) The JAVA Programming Languages Java Virtual Machine Characteristics What is a class? JAVA Standards JAVA Keywords How

More information

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015 COMP-202: Foundations of Programming Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015 Announcements Midterm Exams on 4 th of June (12:35 14:35) Room allocation will be announced soon

More information

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

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time Tester vs. Controller Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG For effective illustrations, code examples will mostly be written in the form of a tester

More information

Java Coding 3. Over & over again!

Java Coding 3. Over & over again! Java Coding 3 Over & over again! Repetition Java repetition statements while (condition) statement; do statement; while (condition); where for ( init; condition; update) statement; statement is any Java

More information

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

Repe$$on CSC 121 Spring 2017 Howard Rosenthal Repe$$on CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Learn the following three repetition structures in Java, their syntax, their similarities and differences, and how to avoid common errors when

More information

download instant at

download instant at 2 Introduction to Java Applications: Solutions What s in a name? That which we call a rose By any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would

More information

CP122 Computer Science I. Chapter 2: Data Types, Variables, and I/O

CP122 Computer Science I. Chapter 2: Data Types, Variables, and I/O CP122 Computer Science I Chapter 2: Data Types, Variables, and I/O Course blogger? QRC Tutoring Tech News! President Obama proposes overhaul of NSA data collection Tech News! President Obama proposes overhaul

More information

Elementary Programming

Elementary Programming Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG Learning Outcomes Learn ingredients of elementary programming: data types [numbers, characters, strings] literal

More information

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

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

COMP 110 Project 1 Programming Project Warm-Up Exercise

COMP 110 Project 1 Programming Project Warm-Up Exercise COMP 110 Project 1 Programming Project Warm-Up Exercise Creating Java Source Files Over the semester, several text editors will be suggested for students to try out. Initially, I suggest you use JGrasp,

More information