Slides0123 - COP 3330 Slides 1/23 Topics Comments, style,...

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

View Full Document Right Arrow Icon
Slides 1/23 COP 3330
Background image of page 1

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

View Full DocumentRight Arrow Icon
Topics Comments, style, and whitespace Type Conversion Literals
Background image of page 2
Automatic Widening Automatic Widening- If two different primitive types are involved in an expression, the less precise one is automatically widened if possible - Example- If f is a double and i is an int, then f+i is a double
Background image of page 3

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

View Full DocumentRight Arrow Icon
Automatic Widening Wideness hierarchy - double - float - long - int - short - byte
Background image of page 4
Automatic Widening char is narrower than int , but neither wider nor narrower than short and byte Arithmetic expressions involving a char , a short , or a byte , are automatically widened to int at least - Example: If b is a byte, b = b + b; is invalid - However: If b is a byte, b += b; is valid
Background image of page 5

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

View Full DocumentRight Arrow Icon
Casts There is no automatic narrowing - Example: If d is a double and i is an int , then i = d; is invalid - Exception: +=, *=, /=, etc. automatically narrow You can force values to be the type you want by using a cast - Example: If d is a double and i is an int , then i = (int)d; is valid boolean s are not compatible with anything else
Background image of page 6
Casts To cast, put the type you want to cast to in parentheses next to the expression you want to cast Casts have very high precedence, so use parentheses - Example: (int)x + 5.0 is a double - Example: (int)(x + 5.0) is an int
Background image of page 7

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

View Full DocumentRight Arrow Icon
Declare constants using the keyword final ( Difference from C ) - Example: final short MAX_VALUE = 32767; - Example: final double PI = 3.141592653589793; Why use constants? -
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/09/2010 for the course CS COP 3330 taught by Professor Douglass during the Spring '09 term at University of Central Florida.

Page1 / 29

Slides0123 - COP 3330 Slides 1/23 Topics Comments, style,...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online