In this tutorial, we will discuss the int keyword in java programming language
In Java programming language, “int” is the keyword used to store the integer value. int allows the creation of methods with the return value. It is a primitive data type in Java programming languages.
It holds 32 bit signed integer value.
integer data type is able to store both unsigned and signed integer.
Syntax
the syntax of keyword an int
int <variable_name> <integer_value>;
Example of keyword an int
int number = 39; int octalNaumber=0377; int hexNumber=0xff;
public class intEx1{ public static void main (String args[]){ int age=20; System.out.println("My age is :"+age); } }
When the above code is executed, it produces the following result
My age is: 20
int add(){ //statements }
Above method is an int method with return any value.
Example int method within class
public class Example _int{ // this is a class in java public static void main(String args[]){ // this is the main method in java } public int add(){ // this is a int method with a return value; } }
Program 2
public class intEx2{ public static void main (String args[]){ my_age(20); } static int my_age(int age){ System.out.println("My age is :"+age); return; } }
When the above code is executed, it produces the following result
My age is :20
There are other Java language keywords that are similar to this keyword
Suggested for you
10 simple ways to add two numbers in Java In this article, we will discuss…
Write a Python program to find the first n prime numbers In this article we…
Python: Calculate Average of odd and even in a list using loops In this post,…
Python: Average of Odd & Even Numbers from User Input In this post, we will…
Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…
Python program to calculate the sum of odd and even numbers in a list In…