Java Program to Convert int to long - The Coding Shala
Hey there, welcome back to another post. In this post, we are going to learn how to convert int to long in Java.
Java Program to Convert int to long
We can convert int to long using the below ways:
- When we convert from smaller data type to larger data type, the Java compiler does it automatically, knowns as implicit conversion.
- Using Long Wrapper class's valueOf() method.
Java Program:
/** * https://www.thecodingshala.com/ */ public class Main { public static void main(String[] args) { int intNumber = 15; // Implicit type casting for smaller to larger data types long longNumber1 = intNumber; System.out.println("Implicit Converted long number is: " + longNumber1); // using Long wrapper class long longNumber2 = Long.valueOf(intNumber); System.out.println("Using Wrapper class converted long number is: " + longNumber2); } }
Output:
Implicit Converted long number is: 15 Using Wrapper class converted long number is: 15
Other Posts You May Like
- Java Program to Take Inputs From User
- Java Program to Find Sum of Digits of a Number
- Java Program to Find the Sum of N Numbers
- Java Program to Take Array Input
- Java Program to Reverse an Array
Please leave a comment below if you like this post or found some errors, it will help me to improve my content.
Comments
Post a Comment