What Is Int Data Type Example?


Heather Bennett

The int data type is one of the fundamental data types in programming. It stands for “integer” and is used to represent whole numbers, both positive and negative, without any decimal places. In this article, we will explore the int data type in depth and provide examples to illustrate its usage.

What is an int data type?

An int data type is a way to store and manipulate whole numbers in programming languages. It has a fixed size, typically 32 bits, which means it can represent values within a specific range. The range of an int can vary depending on the programming language, but it usually includes values from -2,147,483,648 to 2,147,483,647.

Integers are commonly used for counting or indexing purposes because they do not include any fractional or decimal parts. They are also used in mathematical operations where precise results are not required. For example, if you want to count the number of items in a list or keep track of a person’s age, you would use an int data type.


Let’s take a look at a simple example to understand how the int data type works. Suppose we want to write a program that calculates the sum of two numbers.

int num1 = 10;
int num2 = 5;
int sum = num1 + num2;

System.out.println("The sum is: " + sum);

In this example, we declare three variables: num1, num2, and sum, all with the int data type. We assign the values 10 and 5 to num1 and num2, respectively. Then, we use the addition operator (+) to calculate the sum of num1 and num2 and store the result in the variable sum.

Finally, we use the System.println() method to display the result on the console. The output will be “The sum is: 15”.


The int data type is a fundamental data type used to represent whole numbers in programming. It allows us to perform various mathematical operations and store values within a specific range. Understanding how to work with int data type is essential for any programmer.

By using the int data type, you can efficiently perform calculations, count items, and keep track of numerical information in your programs. Remember to always declare variables with the appropriate data type and use them correctly in your code.

Now that you have a better understanding of the int data type, you can start using it in your own programs. Experiment with different values and operations to explore its capabilities further.

Discord Server - Web Server - Private Server - DNS Server - Object-Oriented Programming - Scripting - Data Types - Data Structures

Privacy Policy