-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Java Fundamentals
By :
Integral types are types that have integer values. These are int, long, short, byte, and char.
The int data type is used to represent integers. Integers are 32-bit numbers in the range of -2,147,483,648 to 2,147,483,647. Example of integers are 0, 1, 300, 500, 389 230, 1,345,543, -500, -324,145, and others in that range. For example, to create an int variable to hold a value 5, we write the following:
int num = 5;
The num variable is now an int with a value of five. We can also declare more than one variable of the same type in one line:
int num1, num2, num3, num4, num5;
Here, we have created five variables, all of the int type, and initialized to zero. We can also initialize all of the variables to a specific value, as follows:
int num1 = 1, num2 = 2, num3 = 3, num4 = 4, num5 = 5;
In addition to expressing integers in decimal format, we can also express integers in octal, hexadecimal, and binary format:
As a summary of the aforementioned four formats of representing...
Change the font size
Change margin width
Change background colour