Write a Java Program to convert int type variables to long

Converting an int type variable to a long is a simple task in Java programming.

To convert an int variable to a long, you can simply cast the int variable to a long using the (long) keyword.

In this tutorial, we’ll go through the steps to convert int type variables to long in Java.


Declare an int variable

First, you need to declare an int variable.

For example:

int myInt = 10;

Convert the int variable to long

To convert the int variable to a long, simply cast it to a long using the (long) keyword.

Here’s an example:

long myLong = (long) myInt;

In this example, we’re casting the int variable “myInt” to a long using the (long) keyword and assigning it to a long variable “myLong”.

Use the long variable

Once you’ve converted the int variable to a long, you can use it as a long variable.

For example:

System.out.println("My long variable is: " + myLong);

This will print the value of the long variable “myLong”.


Conclusion

Converting an int type variable to a long is a simple task in Java programming.

You can do it by casting the int variable to a long using the (long) keyword.

Once you’ve converted the int variable to a long, you can use it as a long variable.