Java

What Is Int Keyword In Java ?

A Java basic data type is the int keyword. The range of values that an int data type may store is -231(-2147483648) to 231-1. (2147483647).

public class JavaExample {
  public static void main(String[] args) {
    int num = 123456;
    System.out.println(num);
  }
}

Output:

123456

Note:

  • The integer is 32 bits in size (4 bytes).
  • Integer type variables have a default value of 0.

int as a return type of a method

A method with an int return type is present here. This function takes two integer inputs and outputs the total of those arguments.

public class JavaExample {
  //return type is int
  public static int add(int a, int b){
    return a+b;
  }
  public static void main(String[] args) {
    int sum = add(10,20);
    System.out.println(sum);
  }
}

Output:

30

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button