Home Tutorial Java Corejava Dataconversion Int Conversion from int to String

 
 

Conversion from int to String
Posted on: September 2, 2010 at 12:00 AM
Advertisement
In this tutorial we will learn how to convert an int type value to a String type. You will convert an int value to String by using toString() method.

Conversion from int to String:

In this tutorial we will learn how to convert an int type value to a String type. You will convert an int value  to String by using toString() method.

Description:

This program will take an int value from console and convert this int value to String type data. The line int myint = Integer.parseInt(buffreader.readLine()); is used to read the int value from console and stored in myint variable. The line String mystring = Integer.toString(myint) converts myint int value to mystring String type data.

Code:

import java.io.*;

class inttoString {
	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());
			String mystring = Integer.toString(myint);
			System.out.println("Convert value from int to String is: "
					+ mystring);
		} catch (Exception e) {
			System.out.println(" Error " + e);
		}
	}
};
 

Output:

Download this code

Advertisement

Related Tags for Conversion from int to String:


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