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.

Byron Kiourtzoglou

Byron is a master software engineer working in the IT and Telecom domains. He is an applications developer in a wide variety of applications/services. He is currently acting as the team leader and technical architect for a proprietary service creation and integration platform for both the IT and Telecom industries in addition to a in-house big data real-time analytics solution. He is always fascinated by SOA, middleware services and mobile development. Byron is co-founder and Executive Editor at Java Code Geeks.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button