2.5.4 Declaring Variables to Store Integers

The variable declaration statements in lines 13–15

int number1; // first number to addint number2; // second number to addint sum; // sum of number1 and number2

declare that variables number1, number2 and sum hold data of type int—they can hold integer values (whole numbers such as 72, -1127 and 0). These variables are not yet initialized. The range of values for an int is –2,147,483,648 to +2,147,483,647. [Note: The int values you use in a program may not contain commas.]

Some other types of data are float and double, for holding real numbers, and char, for holding character data. Real numbers contain decimal points, such as in 3.4, 0.0 and -11.19. Variables of type ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.