Java program to convert int type variables to long
httpswww//:.theitroad.com
In Java, you can convert an int
type variable to a long
type variable using a type casting operation. Here's an example:
int num = 100; long l = (long) num; System.out.println("Long value: " + l); // output: 100
In the above example, we define an int
variable num
with a value of 100. We then use type casting to convert num
to a long
variable l
. The (long)
expression is used to tell the Java compiler to treat the int
value as a long
.
After the conversion, the value of l
is 100, which we verify by printing it to the console using the System.out.println
method.
Note that when converting an int
to a long
, the resulting value can be a larger integer than the original int
value. If the int
value is negative, the resulting long
value will also be negative.