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 understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.