Conversion from int to long


 

Conversion from int to long

In this tutorial we will learn how to convert an int type value to long type data.

In this tutorial we will learn how to convert an int type value to long type data.

Conversion from int to long:

In this tutorial we will learn how to convert an int type value to long type data.

Description:

This program will take an int value from console and provide a conversion to long data. The line int myint = Integer.parseInt(buffreader.readLine()); is used to read the int value from console and store in myint variable. The line long mylong = (long)(myint); converts the myint int type value to mylong long type data.

Code:

import java.io.*;

class inttolong {
	public static void main(String[] args) {
		try {
			BufferedReader buffreader = new BufferedReader(
					new InputStreamReader(System.in));
			System.out.println("Enter the int value:");
			int myint = Integer.parseInt(buffreader.readLine());
			long mylong = (long) (myint);
			System.out.println("Convert value from int to long is: " + mylong);
		} catch (Exception e) {
			System.out.println(" Error " + e);
		}
	}
};
 

Output:

Download this code

Ads