Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.

Slides:



Advertisements
Similar presentations
Mod arithmetic.
Advertisements

CSci 1130 Intro to Programming in Java
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.
1 CS150 Introduction to Computer Science 1 Arithmetic Operators.
CS 1 with Robots Variables, Data Types & Math Institute for Personal Robots in Education (IPRE)‏
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
1  Ex: Declare a variable to store user’s age: int age; Prompt the user to enter his/her age: printf (“ How old are you? “); Read / scan the entered value.
Exercises A-Declare a variable of double type with initial value=0.0; B- Declare a constant of String type with initial value=“Good” C- Declare a variable.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Sahar Mosleh California State University San MarcosPage 1 A for loop can contain multiple initialization actions separated with commas Caution must be.
Operators in Python. Arithmetic operators Some operators in Python will look familiar (+, -, *, /) Others are new to you (%, //, **) All of these do work.
Unit 3 Lesson 2: Rational Expressions
Assignment Statements Operator Precedence. ICS111-Java Programming Blanca Polo 2 Assignment, not Equals  An assignment statement changes the value of.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Variables and Expressions, continued CMSC 201. Expressions Anything on the right hand side of the equals is an expression. Expressions can be anything.
Mathematical Calculations in Java Mrs. G. Chapman.
Java Data Types Assignment and Simple Arithmetic.
Variables and Expressions, continued CMSC 201. Expressions Anything on the right hand side of an assignment is an expression. An expression is anything.
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.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
This will all add up in the end. Assignment operator =Simple Assignment operator Arithmetic Operators +Additive operator – Subtraction operator * Multiplication.
Chapter Two Operators and Expressions Lesson Seven.
Numeric Data Types There are six numeric data types: byte, short, int, long, float, and double. Sample variable declarations: int i, j, k; float numberOne,
Doing math In java.
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
Complex Number System Reals Rationals (fractions, decimals) Integers (…, -1, -2, 0, 1, 2, …) Whole (0, 1, 2, …) Natural (1, 2, …) Irrationals.
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
CSCI 1100/1202 January 18, Arithmetic Expressions An expression is a combination of operators and operands Arithmetic expressions compute numeric.
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
Complex Number System Reals Rationals (fractions, decimals) Integers (…, -1, -2, 0, 1, 2, …) Whole (0, 1, 2, …) Natural (1, 2, …) Irrationals.
ICS102 Lecture 1 : Expressions and Assignment King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer.
What will each of the following lines print? System.out.println("number" ); number645 System.out.println("number" + (6 + 4)+ 5); number105 System.out.println(6.
Numeric Data Types There are six numeric data types: byte, short, int, long, float, and double.
1 Section 3.2b Arithmetic Operators Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter 3 Math Operations. Objectives Use the assignment and arithmetic operators. Use operators in output statements. Explain the problem with division.
Expressions.
Expressions.
Subtraction Addition Multiplication Fractions Division 1pt 1 pt 1 pt
7.1/7.2 – Rational Expressions: Simplifying, Multiplying, and Dividing
Multiple variables can be created in one declaration
Assignment and Arithmetic expressions
Type Conversion, Constants, and the String Object
Warm-up September 14, 2017 Change to a decimal: 87% 7%
Math in C The math blocks you've used in Scratch can all be recreated in C!
Operators and Expressions
Arithmetic Operator Operation Example + addition x + y
OPERATORS (1) CSC 111.
Lecture 3 Expressions Richard Gesick.
Arithmetic Expressions in C
Examples of Primitive Values
Arithmetic Expressions & Data Conversions
Variables and Expressions
Math 1-7: Warm-up Multiply. 3(-4) -6(-2) Divide 66 ÷ (-11)
More Maths Programming Guides.
Expressions and Assignment
Variables, Data Types & Math
Doing Arithmetic Today’s lecture is in chapter 2 Assignment statement:
INC 161 , CPE 100 Computer Programming
Data Types and Expressions
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Data Types and Expressions
Arithmetic Expressions & Data Conversions
Data Types and Expressions
Presentation transcript:

Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the types of the operands involved. Remainder operator

Order of Operations Same as math class –() –*, /, % –+, - Here’s an example: –3 + 4*5 - 6/3*4/8 + 2*6 - 4*3*2 – – 24 –10

Integer Division If the two operands are of type int, then integer division occurs An integer division truncates (chops off) any fractional part of the answer. Examples –13/4 = 3 –7/8 = 0 –19/3 = 6

Real Number Division If at least one of the two operands is a double (or float), then a real number division occurs Examples –13/4.0 = 3.25 –13.0/4.0 = 3.25 –19.0/5 = 3.8

Other Issues with Division Variable on the left-hand side of an assignment is of type int, while the expression on the right is a real number –val = 8/5.0, will set val to 1, if val is an int. If the variable on the left-hand side is a double, but the expression on the right is an int, the variable gets set to an int. –val = 8/5, will set val to 1, if val is a double.

Mod Operator A % B returns the remainder when A is divided by B, and A and B MUST BE ints! Examples –12%5 = 2 –19%6 = 1 –14%7 = 0 –19%200 = 19

Initializing Variables If you declare a variable without a value, then that variable initially could equal anything Usually, it’s a good practice to give your variables initial values. Examples –int sum = 0, value = 1; –double price = 0.0;

Defining Constants Use #define Examples –#define FEET_IN_YARD 3 –#define PI Benefits –Code is Easier to Read –If a constant needs to be “changed”, you only need to change it at the top of your program. (ie. if you find out that some program parameter has changed)