Chapter2_3-Operators

S gannouni dr a touir introduction to oop

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: lication/assignment Division/assignment Remainder/assignment Page 17 Dr. S. GANNOUNI & Dr. A. TOUIR += −= ∗= /= %= Introduction to OOP Arithmetic/Assignment Operators • The syntax is leftSide Allways ititis aa Allways is vvariableidentifier. ariable identifier. Op= rightSide ; ItItis either aaliteral | |aa is either literal vvariableidentifier | | ariable identifier aaneexpression. n xpression. ItItis an aarithmetic is an rithmetic operator. operator. • This is equivalent to: leftSide = leftSide Op rightSide ; ⇔ x = x % 5; x*=y+w*z; ⇔ x = x*(y+w*z); • x%=5; • Page 18 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Increment/Decrement Operators Only use ++ or − − when a variable is being incremented/decremented as a statement by itself. x++; is equivalent to x = x+1; x--; is equivalent to x = x-1; Page 19 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Relational Operators • Relational operators compare two values • They Produce a boolean value (true or false) depending on the relationship Operation Is true when a >b a >=b a is greater than or equal to b a ==b a is equal to b a !=b a is not equal to b a <=b a is less than or equal to b a <b Page 20 a is greater than b a is less than b Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Example • int x = 3; • int y = 5; • boolean resu...
View Full Document

Ask a homework question - tutors are online