# Siena CSIS 120 - Numeric Types & Arithmetic Strings - Reading & Writing (44 pages)

Previewing pages 1, 2, 3, 21, 22, 23, 42, 43, 44 of 44 page document
View Full Document

# Numeric Types & Arithmetic Strings - Reading & Writing

Previewing pages 1, 2, 3, 21, 22, 23, 42, 43, 44 of actual document.

View Full Document
View Full Document

## Numeric Types & Arithmetic Strings - Reading & Writing

23 views

Lecture Notes

Pages:
44
School:
Siena College
Course:
Csis 120 - Introduction to Programming

Unformatted text preview:

Chapter 4 Numeric types arithmetic Strings reading writing Numeric Types int integers no fractional part 1 4 0 32483204 double floating point numbers double precision 0 5 3 11111 4 3E24 1E 14 A numeric computation overflows if the result falls outside the range for the number type int n 1000000 System out println n n prints 727379968 Primitive Types Type Description Size int The integer type with range 2 147 483 648 2 147 483 647 4 bytes byte The type describing a single byte with range 128 127 1 byte short The short integer type with range 32768 32767 2 bytes long The long integer type with range 9 223 372 036 854 775 808 9 223 372 036 854 775 807 8 bytes double The double precision floating point type with a range of about 10308 and about 15 significant decimal digits 8 bytes float The single precision floating point type with a range of about 1038 and about 7 significant decimal digits 4 bytes char The character type representing code units in the Unicode encoding scheme 2 bytes boolean The type with the two truth values false and true 1 bit Number Types Floating point Types Rounding errors occur when an exact conversion between numbers is not possible double f 4 35 prints 434 99999999999994 System out println 100 f Java Illegal to assign a floating point expression to an integer variable double balance 13 75 int dollars balance Error Question Which of the following initializations are incorrect and why a int dollars 100 0 b double balance 100 Constants final A final variable is a constant Once its value has been set it cannot be changed Named constants make programs easier to read and maintain Convention Use all uppercase names for constants final final final final double double double double QUARTER VALUE 0 25 DIME VALUE 0 1 NICKEL VALUE 0 05 PENNY VALUE 0 01 payment dollars quarters QUARTER VALUE dimes DIME VALUE nickels NICKEL VALUE pennies PENNY VALUE Constants static final If constant values are needed in several methods declare them together with the

View Full Document

Unlocking...