Java Reference
In-Depth Information
notation 1.3¶10 ɨ4 . (Actually, the computer represents numbers in base 2, not base 10,
but the principle is the same.)
If you need to process numbers with a fractional part, you should use the type called
double , which stands for Ȓdouble precision floating-point numberȓ. Think of a
number in double format as any number that can appear in the display panel of a
calculator, such as 1.3 or ɨ0.333333333.
Do not use commas when you write numbers in Java. For example, 13,000 must be
written as 13000 . To write numbers in exponential notation in Java, use the notation
E n instead of Ȓ¶10 n ȓ. For example, 1.3¶10 ɨ4 is written as 1.3E-4 .
You may wonder why Java has separate integer and floating-point number types.
Pocket calculators don't need a separate integer type; they use floating-point numbers
for all calculations. However, integers have several advantages over floating-point
numbers. They take less storage space, are processed faster, and don't cause rounding
errors. You will want to use the int type for quantities that can never have fractional
parts, such as the length of a string. Use the double type for quantities that can have
fractional parts, such as a grade point average.
There are several other number types in Java that are not as commonly used. We will
discuss these types in Chapter 4 . For most practical purposes, however, the int and
double types are all you need for processing numbers.
In Java, the number types ( int, double , and the less commonly used types) are
primitive types, not classes. Numbers are not objects. The number types have no
methods.
In Java, numbers are not objects and number types are not classes.
However, you can combine numbers with operators such as + and Ċ , as in 10 + n or
n Ċ 1 . To multiply two numbers, use the * operator. For example, 10¶n is written
as 10 * n .
Numbers can be combined by arithmetic operators such as +, Ċ , and * .
Search WWH ::




Custom Search