How to convert int to long in Java
Example:
Input: num=1320
Output: 1320
Approach: 1:
Java
public class IntToLong {public static void main(String[] args) {int num = 1320;long lon = intTolong(num);System.out.println("Long is " + lon);}private static long intTolong(int num) {return num;}}
Approach : 2: Using valueOf()
Java
public class IntToLong {public static void main(String[] args) {int num = 1320;long lon = intTolong(num);System.out.println("Long is " + lon);}private static long intTolong(int num) {return Long.valueOf(num);}}
No comments:
Post a Comment