primitives
int
This is an example of how to use an int type in Java. The int data type is a 32-bit signed two’s complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive). For integral values, this data type is generally the default choice unless there is a reason to choose something else. This data type will most likely be large enough for the numbers your program will use, but if you need a wider range of values, use long instead.
- In order to create a variable of int type for a variable you should type the
int keyword in the variable.Let’s take a look at the code snippet that follows:
package com.javacodegeeks.snippets.basics;
public class IntExample {
public static void main(String[] args) {
int i1 = 242;
int i2 = 3;
System.out.println("Value of int i1 is: " + i1);
System.out.println("Value of int i2 is: " + i2);
}
}
Output:
Value of int i1 is: 242
Value of int i2 is: 3
This was an example of how to use an int type in Java.
