Home Tutorial Java Corejava Dataconversion Int Conversion from int to double

 
 

Conversion from int to double
Posted on: September 2, 2010 at 12:00 AM
Advertisement
In this tutorial we will learn how to convert an int type value to double type data.

Conversion from int to double:

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

Description:

This program will take two int value from console and provide the division of these int values to double type data. The line int a = Integer.parseInt(buffreader.readLine()); is used to read the int value from console and stored in a variable. The line double result = (double)a/b; converts the division result of a and b to double type data.

Code:

import java.io.*;

class inttodouble {
	public static void main(String[] args) {
		try {
			BufferedReader buffreader = new BufferedReader(
					new InputStreamReader(System.in));
			System.out.println("Enter first number:");
			int a = Integer.parseInt(buffreader.readLine());
			System.out.println("Enter second number:");
			int b = Integer.parseInt(buffreader.readLine());
			double result = (double) a / b;
			System.out.println("The result in double type is: " + result);
		} catch (Exception e) {
			System.out.println(" Error " + e);
		}
	}
};
 

Output:

Download this code

Advertisement

Related Tags for Conversion from int to double:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 2, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com