Page 498 - Introduction to Programming with Java: A Problem Solving Approach
P. 498

                464 Chapter 11 Type Details and Alternate Coding Mechanisms
• Type casting allows you to put a numeric value into a numeric variable of a different type, but be care- ful that you don’t get overflow or undesired truncation when you do it.
• When used as a prefix, an increment (++) or decrement (--) operator changes the variable value before that variable participates in other expression operations. When used as a postfix, an increment or decre- ment operator changes the variable value after it participates in other expression operations.
• If a statement contains multiple assignment operators, the rightmost assignment evaluates first.
• It’s sometimes helpful to embed an assignment within a condition, but you should avoid excessive use of
embedded increment, decrement and assignment operations.
• A conditional operator expression provides a compact conditional evaluation. If what’s before the ? is
true, use what’s after the ?. Otherwise, use what’s after the :.
• Short-circuit evaluation means that the JVM stops evaluating an expression whenever the expression’s
outcome becomes certain. Use this feature to avoid illegal operations.
• Use a break statement sparingly to terminate loops prematurely.
• In its extended form, Unicode provides numerical codes for up to a million different characters. You
can specify them as decimal or hexadecimal integers or with a Unicode escape sequence. To see the Unicode characters for codes above 127, you must display them in a GUI window.
Review Questions
§11.2 Integer Types and Floating-Point Types
1. For each integer data type, how many bits of storage are used?
 2. How would you write the decimal constant, 1.602 􏰅 10􏰀19, as a double? Apago PDF Enhancer
3. What is the approximate precision (number of accurate decimal digits) of each of the floating-point types?
§11.3 char Type and the ASCII Character Set
4. How many distinct characters are identified by the basic ASCII character set?
5. What number can you add to an uppercase letter char variable to convert it to lowercase?
§11.4 Type Conversions
6. Assume the declaration:
public final double C = 3.0E10; // speed of light in cm/sec
Write a Java print statement that uses a cast operator to display the value of C in this format: 30000000000
7. Will this statement be OK or will it generate a compile-time error? (OK / error) float price = 66;
8. Will this statement be OK or will it generate a compile-time error? (OK / error) boolean done = (boolean) 0;
9. Will this statement be OK or will it generate a compile-time error? (OK / error) float price = 98.1;
§11.5 Prefix/Postfix Modes for Increment/Decrement Operators 10. What is the value of z after these statements execute?
int z, x = 3;
z = --x;
z += x--;



































































   496   497   498   499   500