{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Intro to Java Web-Notes_Part40

Intro to Java Web-Notes_Part40 - 150 The Modulus Operator...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: 150 The Modulus Operator The modulus operator, %, gives the remainder when the operand on the left is divided by the operand on the right. For example, the value of 5%3 is 2 In long-hand division, this can be visualized as The table below shows some other examples of expressions that involve the modulus operator: —E In the last example the divisor is larger than the dividend -- the quotient is zero and the dividend becomes the remainder: Know The Java Types You should be able to easily identify the basic Java types. For example, you should be able to easily recognize the type of a any Java literal. For example, the type of the literal 15 is int. The type of 15.0 is a double. The type of 'a' is char. The type of true is boolean. The table below shows several literal values and their types E Not a literal value The last entry, a, is not a char because it is lacking the single quotes that identify a character literal (i.e., an ' a ' versus a). It is also missing the double quotes which identify a string literal: " a ". If it is not a char or a string, it must be the name of a variable (a variable name is not a literal value). Maintaining Type If the two operands of a binary operator have the same type, then the value of the expression will have that same type. For example, an integer plus an integer will yield an integer. In the integer expression 5 + 3 the result is the integer 8 An expression that is a double minus a double 10.03 - 1.02 the result is the double 9.01 Since the expression integer expression 3 / 2 will yield an int result, the value is 1 and not 1.5 (1.5 is not an int value). However 3.0 / 2.0 does yield 1.5 (a double divided by a double will yield a double). Here are some examples of expressions, their values, and their type: ——m m —m 5.0/3.0 1.6666 —_nt 7.0/2.0 Mixed Types in an Expression ...
View Full Document

{[ snackBarMessage ]}