COSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand


 Gregory Quinn
 2 years ago
 Views:
Transcription
1 COSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand
2 COSC 236 Web Site I have decided to keep this site for the whole semester I still hope to have blackboard up and running, but you will always find the course material at: From this site you can click on the COSC236 tab to download the PowerPoint lectures, the Quiz solutions and the Laboratory assignments. 2
3 3
4 Review of Quiz 3 4
5 Review of Quiz 3 5
6 Chapter 2 Chapter 2 has TWO distinct parts: The first half (Sections 2.1 and 2.2, pp ) discusses data types, constants and variables This is the topic of today s lecture We will still concentrate on programs that provide output, but now we will be able to do computations and printing out the results The second half (Sections 2.3, 2.4 and 2.5, pp ) introduce our first control structure: the loop This is the topic of next Monday s lecture Loops will allow us to do many things much more easily 6
7 Chapter 2.1 Data types (pp ) Data Type (p. 64) type: A category or set of data values. Constrains the operations that can be performed on data Many languages ask the programmer to specify types Examples: integer, real number, string, character Internally, computers store everything as 1s and 0s 104 = Hi =
8 Chapter 2.1 Data types (pp ) Representation of character and string data in Java Java uses a subset of Unicode to store character data (char) and string data (string) Unicode is 32bit providing binary representations for characters in most languages of the world For a complete list of Unicode see: Java uses only 16bits which allows the representation of what is called the Latin character subset 8
9 Chapter 2.1 Data types (pp ) Representation of character and string data in Java The Java 16bit Unicode is based on an older 7bit ASCII code developed for teletype machines Codes below HEX 20 are teletype control codes HEX 20 through 2F are space and symbols such as those above the numbers on your keyboard HEX 30 through 39 are the numbers 0 through 9 HEX 41 through 5A are the capitol letters HEX 61 through 7A are the small letters 9
10 Chapter 2.1 Data types (pp ) Representation of character and string data in Java String data (string) is enclosed in double quotes: This is string data a Character data (char) is enclosed in single quotes T, h, I, s,, I, s,, c, h, a, r,, d, a, t, a a Illegal: This is char data 10
11 Chapter 2.1 Data types (pp ) Java's primitive types (p. 64) primitive types: 8 simple types for numbers, text, etc. Java also has object types, which we'll talk about later ± ± Why does Java distinguish integers vs. real numbers? 11
12 Chapter 2.1 Data types (pp ) Expressions (pp ) expression: A value or operation that computes a value. Examples: * 5 (7 + 2) * 6 / 3 42 The simplest expression is a literal value (Example: 42). A complex expression can use operators and parentheses. 12
13 Chapter 2.1 Data types (pp ) Arithmetic operators (pp ) operator: Combines multiple values or expressions. + addition  subtraction (or negation) * multiplication / division % modulus (a.k.a. remainder) NOT PERCENT! As a program runs, its expressions are evaluated evaluates to 2 System.out.println(3 * 4); prints 12 How would we print the text 3 * 4? System.out.println( 3 * 4 ); 13
14 Chapter 2.1 Data types (pp ) Integer division with / (pp ) When we divide integers, the quotient is also an integer. 14 / 4 is 3, not 3.5; 45 / 10 = 4; 1425 / 27 = ) ) ) More examples: 32 / 5 is 6 84 / 10 is / 100 is 1 Dividing by 0 causes an error when your program runs. 14
15 Chapter 2.1 Data types (pp ) Integer remainder with % (pp ) The % operator computes the remainder from integer division. 14 % 4 is % 5 is ) 14 5 ) What is the result? 45 % 6 2 % 2 8 % % error Applications of % operator: Obtain last digit of a number: % 10 is 7 Obtain last 4 digits: % is 6489 See whether a number is odd: 7 % 2 is 1, 42 % 2 is 0 15
16 Chapter 2.1 Data types (pp ) Precedence (pp ) precedence: Order in which operators are evaluated. Generally operators evaluate lefttoright is (12)  3 which is 4 But * / % have a higher level of precedence than * 4 is / 2 * * is 18 Parentheses can force a certain order of evaluation: (1 + 3) * 4 is 16 Please Excuse My Dear Aunt Sally P = Parenthesis E = Exponentiation M/D = Multiply and Divide A/S = Add and Subtract Spacing does not affect order of evaluation 1+3 * 42 is 11 16
17 Chapter 2.1 Data types (pp ) Precedence examples (pp ) 1 * * 5 % 4 \_/ * 5 % 4 \_/ % 4 \ / \ / % 3 * 29 \_/ * 29 \ / \ / 59 \ / 4 17
18 Chapter 2.1 Data types (pp ) Precedence examples (pp ) What values result from the following expressions? 9 / % * 5 7 * % 100 / 5 6 * 39 / 4 (57) * (18 % (1712)) = = 47 48/5 = /4 = 18 2 = 16 (2)*4 = 8 6+(18%5) = 6+3 = 9 18
19 Chapter 2.1 Data types (pp ) Mixing Types and Casting (pp ) Examples: 6.022, 42.0, 2.143e17 Placing.0 or. after an integer makes it a double. The operators +  * / % () all still work with double. / produces an exact answer: 15.0 / 2.0 is 7.5 Precedence is the same: () before * / % before +  But What Happens when we mix int and double? When one operand is int and the other double, the int is converted to double = x Please Excuse My Dear Aunt Sally P = Parenthesis E = Exponentiation M/D = Multiply and Divide A/S = Add and Subtract 19
20 Chapter 2.1 Data types (pp ) Real number example 2.0 * * 4.0 / 2.0 \ / * 4.0 / 2.0 \ / / 2.0 \ / \ / 9.3 Mixed Example 2 * * 4 / 2 \ / * 4 / 2 \ / / 2 \ / \ /
21 Chapter 2.1 Data types (pp ) When int and double are mixed, the result is a double. 4.2 * 3 = 4.2 * 3.0 = 12.6 Mixing types (pp ) The conversion is peroperator, affecting only its operands. 7 / 3 * / 2 \_/ 2 * / 2 \ / / 2 \_/ \ / / 2 is 1 above, not / 3 * / 4 \ / * / 4 \ / / 4 \_/ \ / \ /
22 Chapter 2.1 Data types (pp ) Casting (pp ) You can change one type into another through casting The most common is to change what would normally be a double into an int (int) (5.0/3.0) = 1 (int)(10*(11.4 % 3))/10.0 = 2.4 Note: N % D = (N/D (int)(n/d))*d 22
23 Chapter 2.1 Data types (pp ) String concatenation string concatenation: Using + between a string and another value to make a longer string. "hello" + 42 is "hello42" 1 + "abc" + 2 is "1abc2" "abc" is "abc12" "abc" is "3abc" "abc" + 9 * 3 is "abc27" "1" + 1 is "11" "abc" is "3abc" Use + to print a string and an expression's value together. System.out.println("Grade: " + ( ) / 2); Output: Grade:
24 Chapter 2.2 Variables (pp ) Use of Variables (pp ) variable: A piece of the computer's memory that is given a name and type, and can store a value. Like preset stations on a car stereo, or cell phone speed dial: Steps for using a variable: Declare it  state its name and type Initialize it  store a value into it Use it  print it or use it as part of an expression 24
25 Chapter 2.2 Variables (pp ) Step 1: Declaration (p. 80) variable declaration: Sets aside memory for storing a value. Variables must be declared before they can be used. Syntax: type name; The name is an identifier. int x; x double mygpa; mygpa 25
26 Chapter 2.2 Variables (pp ) Step 2: Assignment assignment: Stores a value into a variable. The value can be an expression; the variable stores its result. Syntax: name = expression; int x; x = 3; double mygpa; mygpa = ; x 3 mygpa
27 Chapter 2.2 Variables (pp ) Step 3: Using variables Once given a value, a variable can be used in expressions: int x; x = 3; System.out.println("x is " + x); // x is 3 System.out.println(5 * x  1); // 5 * 31 You can assign a value more than once: int x; x = 3; System.out.println(x + " here"); // 3 here x = 4 + 7; System.out.println("now x is " + x); // now x is 11 x
28 Chapter 2.2 Variables (pp ) Declaration/initialization A variable can be declared/initialized in one statement. Syntax: type name = value; double mygpa = 3.95; int x = (11 % 3) + 12; mygpa 3.95 x 14 28
29 Chapter 2.2 Variables (pp ) Assignment and algebra (pp ) Assignment uses =, but it is not an algebraic equation. = means, "store the value at right in variable at left" The right side expression is evaluated first, and then its result is stored in the variable at left. What happens here? int x = 3; x = x + 2; //??? NOTE: This is an illeagal algebraic expression No value of x can satisfy the equation x = x + 2. x 35 29
30 Chapter 2.2 Variables (pp ) Assignment and types (pp ) A variable can only store a value of its own type. int x = 2.5; // ERROR: incompatible types An int value can be stored in a double variable. The value is converted into the equivalent real number. double mygpa = 4; double avg = 11 / 2; Why does avg store 5.0 and not 5.5? mygpa 4.0 avg
31 Chapter 2.2 Variables (pp ) Compiler errors (pp ) A variable can't be used until it is assigned a value. int x; System.out.println(x); // ERROR: x has no value You may not declare the same variable twice. int x; int x; int x = 3; int x = 5; How can this code be fixed? // ERROR: x already exists // ERROR: x already exists Int x = 3; x = 5; 31
32 Chapter 2.2 Variables (pp ) Printing a variable's value (pp ) Use + to print a string and a variable's value on one line. double grade = ( ) / 3.0; System.out.println("Your grade was " + grade); int students = ; System.out.println("There are " + students + " students in the course."); Output: Your grade was 83.2 There are 65 students in the course. 32
33 Chapter 2.2 Variables (pp ) Receipt example What's bad about the following code? public class Receipt { public static void main(string[] args) { // Calculate total owed, assuming 8% tax / 15% tip System.out.println("Subtotal:"); System.out.println( ); System.out.println("Tax:"); System.out.println(( ) *.08); System.out.println("Tip:"); System.out.println(( ) *.15); System.out.println("Total:"); System.out.println( ( ) *.08 + ( ) *.15); } } The subtotal expression ( ) is repeated To many println statements 33
34 Chapter 2.2 Variables (pp ) Receipt question (pp ) How can you improve the receipt program using variables? public class Receipt { public static void main(string[] args) { // Calculate total owed, assuming 8% tax / 15% tip System.out.println("Subtotal:"); System.out.println( ); System.out.println("Tax:"); System.out.println(( ) *.08); System.out.println("Tip:"); System.out.println(( ) *.15); System.out.println("Total:"); System.out.println( ( ) *.15 + ( ) *.08); } } 34
35 Chapter 2.2 Variables (pp ) Receipt answer (pp ) public class Receipt { public static void main(string[] args) { // Calculate total owed, assuming 8% tax / 15% tip int subtotal = ; double tax = subtotal *.08; double tip = subtotal *.15; double total = subtotal + tax + tip; } } System.out.println("Subtotal: " + subtotal); System.out.println("Tax: " + tax); System.out.println("Tip: " + tip); System.out.println("Total: " + total); 35
36 Chapter 2.2 Variables (pp ) Increment/Decrement Operators (pp ) It is a common situation in programming to need to add a fixed amount to a variable: x = x + 1; y = y + 2; z = z + 5; Java provides the += assignment operator to implement this: x += 1; y += 2; z += 5; 36
37 Chapter 2.2 Variables (pp ) Increment/Decrement Operators (pp ) It is also common situation in programming to need to subtract a fixed amount from a variable: x = x  1; y = y  2; z = z  5; Java provides the = assignment operator to implement this: x = 1; y = 2; z = 5; 37
38 Chapter 2.2 Variables (pp ) Increment/Decrement Operators (pp ) It is also common situation in programming to need to multiply a variable by a fixed amount: x = x * 2; y = y * 3; z = z * 5; Java provides the *= assignment operator to implement this: x *= 2; y *= 3; z *= 5; 38
39 Chapter 2.2 Variables (pp ) Increment/Decrement Operators (pp ) It is also common situation in programming to need to divide a variable by a fixed amount: x = x / 2; y = y / 3; z = z / 5; Java provides the /= assignment operator to implement this: x /= 2; y /= 3; z /= 5; 39
40 Chapter 2.2 Variables (pp ) Increment/Decrement Operators (pp ) The special cases of increment by one and decrement by one are so common that Java provides a special operator for these increment and decrement unary operations: x = x + 1; y = y  1; Java provides the ++ increment unary operator: x++; (postincrement) ++x; (preincrement) and the  decrement unary operator: y; (postdecrement) x; (predecrement) 40
41 Chapter 2.2 Variables (pp ) Increment/Decrement Operators (pp ) The special cases of increment by one and decrement by one are so common that Java provides a special operator for these increment and decrement unary operations: x = x + 1; x++; (postincrement) ++x; (preincrement) y = y  1; y; (postdecrement) x; (predecrement) The postoperators use the value of the variable before they increment or decrement the variable while the preoperators use the variable after they increment or decrement the variable. This makes no difference to the final value of the variable and hence, no difference in these expressions however, in branch and loop statements it can make a difference. 41
42 Chapter 2.2 Variables (pp ) Increment/Decrement Operators (pp ) 42
43 Chapter 2.2 Variables (pp ) Variables and Mixing Types (pp ) A common programming mistake is to improperly use integers in a division operation: This results in the following output: 43
44 Chapter 2.2 Variables (pp ) Variables and Mixing Types (pp ) An easy fix is to move the 100 to the first operation changing it to 100.0: This results in the following output: 44
45 Assignments for this week 1. Laboratory for Chapter 2 due in one week (Monday 2/17) NOTE: Due date on handout is incorrect IMPORTANT: When you me your laboratory Word Document, be sure it is all in one file 2. Read more of Chapter 2 for next Monday (pp ) 3. Be sure to complete Quiz 4 before leaving class tonight This is another program to write You must demonstrate the program to me before you leave lab 45
Building Java Programs
Building Java Programs Chapter 2 Lecture 21: Expressions and Variables reading: 2.12.2 1 Data and expressions reading: 2.1 selfcheck: 14 videos: Ch. 2 #1 2 Data types type: A category or set of data
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 21: Expressions and Variables reading: 2.12.2 Copyright 2009 by Pearson Education Data and expressions reading: 2.1 selfcheck: 14 videos: Ch. 2 #1 Copyright
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 21: Expressions and Variables reading: 2.12.2 1 2 Data and expressions reading: 2.1 3 The computer s view Internally, computers store everything as 1 s and 0
More informationTopic 4 Expressions and variables
Topic 4 Expressions and variables "Once a person has understood the way variables are used in programming, he has understood the quintessence of programming." Professor Edsger W. Dijkstra Based on slides
More informationLecture 2: Operations and Data Types
Lecture 2: Operations and Data Types Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson 2013. All rights reserved. Data types type: A category or set
More informationBuilding Java Programs. Chapter 2: Primitive Data and Definite Loops
Building Java Programs Chapter 2: Primitive Data and Definite Loops Copyright 2008 2006 by Pearson Education 1 Lecture outline data concepts Primitive types: int, double, char (for now) Expressions: operators,
More informationBuilding Java Programs Chapter 2
Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. Data types type: A category or set of data values. Constrains the operations that can
More informationBuilding Java Programs Chapter 2. bug. Primitive Data and Definite Loops. Copyright (c) Pearson All rights reserved. Software Flaw.
Building Java Programs Chapter 2 bug Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. 2 An Insect Software Flaw 3 4 Bug, Kentucky Bug Eyed 5 Cheesy Movie 6 Punch Buggy
More informationBuilding Java Programs Chapter 2
Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. bug 2 An Insect 3 Software Flaw 4 Bug, Kentucky 5 Bug Eyed 6 Cheesy Movie 7 Punch Buggy
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 21: Expressions and Variables reading: 2.12.2 1 Variables reading: 2.2 selfcheck: 115 exercises: 14 videos: Ch. 2 #2 2 Receipt example What's bad about the
More informationIntroduction to Computer Programming
Introduction to Computer Programming Lecture 2 Primitive Data and Stepwise Refinement Data Types Type  A category or set of data values. Constrains the operations that can be performed on data Many languages
More informationData and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence
Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public
More informationChapter Legal intliterals: 22, 1, and d Results of intexpressions:
Chapter 2 1. Legal intliterals: 22, 1, and 6875309 2. d. 11 3. Results of intexpressions: a. 8 b. 11 c. 6 d. 4 e. 33 f. 16 g. 6.4 h. 6 i. 30 j. 1 k. 7 l. 5 m. 2 n. 18 o. 3 p. 4 q. 4 r. 15 s. 8 t. 1 4.
More informationWhat we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements
Topic 4 Variables Once a programmer has understood the use of variables, he has understood the essence of programming Edsger Dijkstra What we will do today Explain and look at examples of primitive data
More informationCOSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.classnotes.us From this site you can click on the COSC236
More informationCS 112 Introduction to Programming
CS 112 Introduction to Programming Variables; Type Casting; Using Variables in for Loops Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 4326400 Email: yry@cs.yale.edu
More informationCS 112 Introduction to Programming
CS 112 Introduction to Programming Java Primitive Data Types; Arithmetic Expressions Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 4326400 Email: yry@cs.yale.edu
More informationAdmin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example
Admin CS 112 Introduction to Programming q Programming assignment 2 to be posted tonight Java Primitive Data Types; Arithmetic Expressions Yang (Richard) Yang Computer Science Department Yale University
More informationCSE 142, Summer 2014
CSE 142, Summer 2014 Lecture 2: Static Methods Expressions reading: 1.4 2.1 Algorithms algorithm: A list of steps for solving a problem. Example algorithm: "Bake sugar cookies" Mix the dry ingredients.
More informationBuilding Java Programs
Building Java Programs Chapter 2: Primitive Data and Definite Loops These lecture notes are copyright (C) Marty Stepp and Stuart Reges, 2007. They may not be rehosted, sold, or modified without expressed
More informationCSE 142, Summer 2015
CSE 142, Summer 2015 Lecture 2: Static Methods Expressions reading: 1.4 2.1 The Mechanical Turk 2 Escape Characters System.out.println( ab\ \\\\\\/\td ); Output: ab \\\/ d 3 Algorithms algorithm: A list
More informationInformation Science 1
Topics covered Information Science 1 Terms and concepts from Week 8 Simple calculations Documenting programs Simple Calcula,ons Expressions Arithmetic operators and arithmetic operator precedence Mixedtype
More informationPrimitive data, expressions, and variables
How the computer sees the world Primitive data, expressions, and variables Readings:.. Internally, the computer stores everything in terms of s and 0 s Example: h 0000 "hi" 0000000 0 0000 How can the computer
More informationCOMP Primitive and Class Types. Yi Hong May 14, 2015
COMP 110001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to
More informationInformation Science 1
Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting
More informationBuilding Java Programs
Building Java Programs Chapter 1 Lecture 2: Static Methods reading: 1.41.5 (Slides adapted from Stuart Reges, Hélène Martin, and Marty Stepp) 2 Recall: structure, syntax class: a program public class
More informationBasics of Java Programming
Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements  A statement is some action or sequence of actions, given as a command in code. A statement
More informationDeclaration and Memory
Declaration and Memory With the declaration int width; the compiler will set aside a 4byte (32bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier
More informationCOSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.classnotes.us From this site you can click on the COSC236
More informationModule 2  Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1
Module 2  Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions
More informationCOSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.classnotes.us or http://www.classnotes.info or http://www.lecturenotes.tripod.com
More informationObjectOriented Programming
ObjectOriented Programming Java Syntax Program Structure Variables and basic data types. Industry standard naming conventions. Java syntax and coding conventions If Then Else Case statements Looping (for,
More informationLECTURE 3 C++ Basics Part 2
LECTURE 3 C++ Basics Part 2 OVERVIEW Operators Type Conversions OPERATORS Operators are special builtin symbols that have functionality, and work on operands. Operators are actually functions that use
More informationCSCI 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 informationLecture Set 4: More About Methods and More About Operators
Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Shortcircuiting main method public static
More informationCSc 110, Spring 2017 Lecture 3: Expressions, Variables and Loops. Adapted from slides by Marty Stepp and Stuart Reges
CSc 110, Spring 2017 Lecture 3: Expressions, Variables and Loops Adapted from slides by Marty Stepp and Stuart Reges 1 Data and expressions 2 Data types Internally, computers store everything as 1s and
More informationOperators. Lecture 3 COP 3014 Spring January 16, 2018
Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special builtin symbols that have functionality, and work on operands operand an input to an operator Arity  how many operands an operator
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationCMPT 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 informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 21 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationCOSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.classnotes.us or http://www.classnotes.info or http://www.lecturenotes.tripod.com
More informationChapter 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 informationLecture Set 4: More About Methods and More About Operators
Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Shortcircuiting main method public static
More informationJAVA OPERATORS GENERAL
JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
More informationOperators. Java operators are classified into three categories:
Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.
More informationBasic Operations jgrasp debugger Writing Programs & Checkstyle
Basic Operations jgrasp debugger Writing Programs & Checkstyle Suppose you wanted to write a computer game to play "Rock, Paper, Scissors". How many combinations are there? Is there a tricky way to represent
More informationProgram 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 informationCOSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.classnotes.us or http://www.classnotes.info or http://www.lecturenotes.tripod.com
More informationExpressions and Data Types CSC 121 Fall 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and
More informationLecture 3 Tao Wang 1
Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers
More informationCIS 110: Introduction to Computer Programming
CIS 110: Introduction to Computer Programming Lecture 3 Express Yourself ( 2.1) 9/16/2011 CIS 110 (11fa)  University of Pennsylvania 1 Outline 1. Data representation and types 2. Expressions 9/16/2011
More informationEx: If you use a program to record sales, you will want to remember data:
Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:
More information4 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 informationChapter 2 ELEMENTARY PROGRAMMING
Chapter 2 ELEMENTARY PROGRAMMING Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk ١ Objectives To write Java programs to perform simple
More informationCSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018
CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values
More informationCONTENTS: 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 highlevel language Java,
More informationCOSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.classnotes.us From this site you can click on the COSC236
More informationLecture 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 informationDATA TYPES AND EXPRESSIONS
DATA TYPES AND EXPRESSIONS Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment Mathematical
More informationJAVA 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 informationCS 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 informationUNIT 3 Introduction to C++
UNIT 3 Introduction to C++ C++ Character Sets: Letters AZ, az Digits 09 Special Symbols Space +  * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationJava provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:
Basic Operators Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions
More informationMODULE 02: BASIC COMPUTATION IN JAVA
MODULE 02: BASIC COMPUTATION IN JAVA Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data
More informationChapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics
Java Programming, Sixth Edition 21 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional
More informationChapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:
Java Programming, Eighth Edition 21 Chapter 2 Using Data A Guide to this Instructor s Manual: We have designed this Instructor s Manual to supplement and enhance your teaching experience through classroom
More informationCOMP 110 Introduction to Programming. What did we discuss?
COMP 110 Introduction to Programming Fall 2015 Time: TR 9:30 10:45 Room: AR 121 (Hanes Art Center) Jay Aikat FB 314, aikat@cs.unc.edu Previous Class What did we discuss? COMP 110 Fall 2015 2 1 Today Announcements
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting
More informationFull file at
Java Programming, Fifth Edition 21 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional
More informationSSEA Computer Science: CS106A. Dr. Cynthia Lee Lecturer in Computer Science Stanford
SSEA Computer Science: CS106A Dr. Cynthia Lee Lecturer in Computer Science Stanford Topics for today Learn how to harness computing power to solve problems. To that end: Introduce Java programming language
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 2: Data and Expressions CS 121 1 / 51 Chapter 1 Terminology Review
More informationData and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:
Data and Expressions Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration And Use Of Variables Expressions
More informationProgramming with Java
Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 20172018 Objectives q By the end of this lecture you should be able to : ü Know rules
More informationSSEA Computer Science: Track A. Dr. Cynthia Lee Lecturer in Computer Science Stanford
SSEA Computer Science: Track A Dr. Cynthia Lee Lecturer in Computer Science Stanford Topics for today Introduce Java programming language Assignment and type casting Expressions Operator precedence Code
More informationBASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I
BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment
More informationSir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )
Sir Muhammad Naveed Arslan Ahmed Shaad (1163135 ) Muhammad Bilal ( 1163122 ) www.techo786.wordpress.com CHAPTER: 2 NOTES: VARIABLES AND OPERATORS The given Questions can also be attempted as Long Questions.
More informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 21 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More informationCS111: PROGRAMMING LANGUAGE II
1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables
More informationEntry 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 CHENWEI WANG For now, all your programming exercises will
More informationLecture 6. Assignments. Summary  Variables. Summary Program Parts 1/29/18. Reading: 3.1, 3.2, 3.3, 3.4
Assignments Lecture 6 Complete for Project 1 Reading: 3.1, 3.2, 3.3, 3.4 Summary Program Parts Summary  Variables Class Header (class name matches the file name prefix) Class Body Because this is a program,
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 2: Data and Expressions CS 121 1 / 53 Chapter 2 Part 1: Data Types
More informationCourse Outline. Introduction to java
Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.
More informationChapter 2. Elementary Programming
Chapter 2 Elementary Programming 1 Objectives To write Java programs to perform simple calculations To obtain input from the console using the Scanner class To use identifiers to name variables, constants,
More informationJava enum, casts, and others (Select portions of Chapters 4 & 5)
Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The
More informationTester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time
Tester vs. Controller Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHENWEI WANG For effective illustrations, code examples will mostly be written in the form of a tester
More informationCOMP202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods
COMP202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,
More informationExpressions and Data Types CSC 121 Spring 2017 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationIntroduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language
Chapter 1 Getting Started Introduction To Java Most people are familiar with Java as a language for Internet applications We will study Java as a general purpose programming language The syntax of expressions
More informationChapter 2 Primitive Data Types and Operations. Objectives
Chapter 2 Primitive Data Types and Operations Prerequisites for Part I Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs,
More informationElementary Programming
Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHENWEI WANG Learning Outcomes Learn ingredients of elementary programming: data types [numbers, characters, strings] literal
More informationSlide 1 CS 170 Java Programming 1 Expressions Duration: 00:00:41 Advance mode: Auto
CS 170 Java Programming 1 Expressions Slide 1 CS 170 Java Programming 1 Expressions Duration: 00:00:41 What is an expression? Expression Vocabulary Any combination of operators and operands which, when
More information9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?
Arithmetic Operators Section 2.15 & 3.2 p 6063, 8189 1 Today Arithmetic Operators & Expressions o Computation o Precedence o Associativity o Algebra vs C++ o Exponents 2 Assigning floats to ints int
More informationSOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)
SOFTWARE DEVELOPMENT 1 Operators 2018W (Institute of Pervasive Computing, JKU Linz) OPERATORS Operators are required to form expressions. Depending on the number of operands they take, they are called:
More informationcis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1
topics: introduction to java, part 1 cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 cis20.1fall2007sklarleci.2 1 Java. Java is an objectoriented language: it is
More informationGetting 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 informationAccelerating Information Technology Innovation
Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 02 Variables and Operators Agenda Variables Types Naming Assignment Data Types Type casting Operators
More informationLecture 3 Operators MIT AITI
Lecture 3 Operators MIT AITI  2004 What are Operators? Operators are special symbols used for mathematical functions assignment statements logical comparisons Examples: 3 + 5 // uses + operator 14 + 5
More information