Chapter2_3-Operators

0 3 gives 333333 as we can see if we divide two

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: ntroduction to OOP Example Example of division issues: 10 / 3 gives 3 10.0 / 3 gives 3.33333 As we can see, •if we divide two integers we get an integer result. •if one or both operands is a floating-point value we get a floating-point result. Page 7 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Modulus Generates the remainder when you divide two integer values. 5%3 gives 2 5%5 gives 0 5%4 gives 1 5%10 gives 5 Modulus operator is most commonly used with integer operands. If we attempt to use the modulus operator on floating-point values we will garbage! Page 8 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Order of Precedence ( ) evaluated first, inside-out ∗, /, or % evaluated second, left-to-right +, − evaluated last, left-to-right Page 9 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP Basic Assignment Operator • We assign a value to a variable using the basic assignment operator (=). • Assignment operator stores a value in memory. • The syntax is leftSide Examples: Allways ititis aa Allways is vvariableidentifier. ariable identifier. = rightSide ; ItItis either aaliteral | |aa is either literal vvariableidentifier | | ariable identifier aaneexpression. n xpression. i = 1; start = i; sum = firstNumber + secondNumber; avg = (one + two + three) / 3; Page 10 Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP The Right Side of the Assignment Operator • The Java assignment operator assigns the value on t...
View Full Document

Ask a homework question - tutors are online