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