Int data type is a 32-bit signed two's complement integer.
Minimum value is - 2,147,483,648 (-2^31)
Maximum value is 2,147,483,647(inclusive) (2^31 -1)
Integer is generally used as the default data type for integral values unless there is a concern about memory.
The default value is 0
Example: int a = 100000, int b = -200000
public class IntDataType {
public static void main(String []args) {
// this is declaration and initialization of variable a
// datatype is int
int a = 10000;
// this is declaration and initialization of variable b
// datatype is int
int b = -5000;
System.out.println(a); // it will print a variable
System.out.println(b); // it will print b variable
}
}
10000
-5000
Press any key to continue . . .
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.