Operators © Copyright 2014, Fred McClurg All Rights Reserved.

Slides:



Advertisements
Similar presentations
Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands.
Advertisements

Arithmetic Calculations
Javascript Essentials How do I write it??  Start Homesite  Between the start and end BODY tags type: 
Friday, December 08, 2006 “Experience is something you don't get until just after you need it.” - Olivier.
Introduction to PHP and MySQL Kirkwood Center for Continuing Education By Fred McClurg, © Copyright 2010, All Rights Reserved 1.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
CIS 234: Order of Operations, Shortcut & Other Operators Dr. Ralph D. Westfall February, 2004.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
JavaScript, Third Edition
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
CSci 142 Data and Expressions. 2  Topics  Strings  Primitive data types  Using variables and constants  Expressions and operator precedence  Data.
Expressions, Data Conversion, and Input
***** SWTJC STEM ***** Chapter 2-3 cg 29 Java Operators Recall Java’s programming components: Packages - Collection of classes (Programs) Classes - Collections.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
2440: 211 Interactive Web Programming Expressions & Operators.
Object-Oriented Programming Using C++ Third Edition Chapter 2 Evaluating C++ Expressions.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Numeric Types, Expressions, and Output ROBERT REAVES.
CSE1301 Computer Programming Lecture 5: C Primitives 2 Corrections.
LESSON 6 – Arithmetic Operators
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Operators in Python. Arithmetic operators Some operators in Python will look familiar (+, -, *, /) Others are new to you (%, //, **) All of these do work.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Assignment Statements Operator Precedence. ICS111-Java Programming Blanca Polo 2 Assignment, not Equals  An assignment statement changes the value of.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Numbers © Copyright 2014, Fred McClurg All Rights Reserved.
Arithmetic in Pascal A Short Glance We will learn the followings in this chapter Arithmetic operators Order of precedence Assignment statements Arithmetic.
Operators. Today’s Learning Goals … Understand the purpose of JavaScript operators Explore the mathematical operators Find out about the assignment operators.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
Boolean Logic Logical Operators Comparison Operators Truth tables.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Data Types Declarations Expressions Data storage C++ Basics.
Mathematical Calculations in Java Mrs. C. Furman.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
This will all add up in the end. Assignment operator =Simple Assignment operator Arithmetic Operators +Additive operator – Subtraction operator * Multiplication.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Java Operator Precedence Operator Meaning Assoc. ===========================================================.
Doing math In java.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
COMP 110: Spring Announcements Lab 1 due Wednesday at Noon Assignment 1 available on website Online drop date is today.
Operators.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
More Python Proglan Python Session 2. Lists  Lists are like flexible arrays. They can contain as many variables as you wish, and all variable types are.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
AOIT Introduction to Programming Unit 2, Lesson 6 Arithmetic Operators and Operator Precedence Copyright © 2009–2012 National Academy Foundation. All rights.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
Operators & Expressions
Lecture 3 Java Operators.
University of Central Florida COP 3330 Object Oriented Programming
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Operators Operators are symbols such as + (addition), - (subtraction), and * (multiplication). Operators do something with values. $foo = 25; $foo – 15;
University of Central Florida COP 3330 Object Oriented Programming
Nahla Abuel-ola / WIT.
Variable Declaration, Data types, Expressions
Operators and Expressions
Arithmetic Operator Operation Example + addition x + y
Review # 2 Math 8.
With Assignment Operator
Conversion Check your class notes and given examples at class.
Learning Intention I will learn about concatenation and arithmetic operators.
Operators In Java Programming By Rajanikanth B.
Chapter 4: Expression and Operator
OBJECT ORIENTED PROGRAMMING I LECTURE 4 PART 2 GEORGE KOUTSOGIANNAKIS
DATA TYPES There are four basic data types associated with variables:
Primitive Data Types and Operators
Presentation transcript:

Operators © Copyright 2014, Fred McClurg All Rights Reserved

Basic Arithmetic Operators Examples: 2 + 5; // ; // ; // -4 3 * 4; // / 6; // 6 36 / 5; // arithOper.html

3 Modulo Defined Discussion: The modulo is the integer remainder result from the division of two numbers. Example: 5 / 2 = 2 with a remainder (or modulo) of 1. Purpose:  Modulo is often used to determine if a value is an even multiple.  Modulo is also used to determine if a value is an even or odd number (multiple of two).

Modulo Operator Examples // remainder of 1 after division console.log( 21 % 5 ); // 1 /* 5 is a multiple of 20 because it's evenly divisible by 5 */ console.log( 20 % 5 ); // 0 /* 21 is an odd number because it is not evenly divisible by 2 */ console.log( 21 % 2 ); // 1 /* 20 is an even number because it is evenly divisible by 2 */ console.log( 20 % 2 ); // 0 4 moduloOper.html

String Operator Discussion: The plus “ + ” symbol can also be used to concatenate (i.e. join) multiple strings together. Examples: // spiderman (concatenation) var hero = "spider" + "man"; console.log( hero ); 5 strOper.html

6 Operator Precedence Discussion: Every operator has a precedence. The order in which arithmetic is performed is based upon that precedence. The parenthesis “()” is used to force precedence. Examples: // default precedence order // multiplication is performed first * 10; // 44 // use parenthesis to force precedence ( ) * 10; // 80 operOrder.html

Numeric Short Cut Operators Discussion: The Short Cut Operators (also known as Assignment Operators) are available for all arithmetic operators. Examples: var browser = 0; count += 4; // count = count + 4; count -= 2; // count = count - 2; count *= 3; // count = count * 3; count /= 2; // count = count / 2; count %= 2; // count = count % 2; 7 shortOpNum.html

Discussion: The “ += ” Short Cut Operator (also known as Assignment Operator) also works to concatenate strings. Examples: var quote = ""; // initialize value quote += "Please accept my resignation. "; quote += "I don't want to belong "; quote += "to any club that will accept "; quote += "people like me as a member. "; quote += "-- Groucho Marx"; String Short Cut Operator 8 shortOpStr.html

Unary Operators: Increment and Decrement Discussion: The Increment Operator “ ++ ” and Decrement Operator “ -- ” is a Short Cut Operator for adding and subtracting one from a value. Examples: var countInc = 0; countInc++; // count = count + 1; console.log( countInc ); // 1 var countDec = 2; countDec--; // count = count - 1; console.log( countDec ); // 1 9 unaryOper.html

Prefix Increment Operator Discussion: The Prefix Increment Operator “ ++x ” performs the addition first and then the assignment. Example: var count = 0; // Prefix order of operation: // 1. count + 1 // 2. prefix = count var prefix = ++count; console.log( count ); // 1 console.log( prefix ); // 1 10 prefixIncOp.html

Postfix Increment Operator Discussion: The Postfix Increment Operator “ x++ ” performs the assignment first and then the addition. Example: var index = 0; // Postfix order of operation: // 1. postfix = index // 2. index + 1 var postfix = index++; console.log( postfix ); console.log( index ); 11 postfixIncOp.html Question: What is the value of prefix?