Home Tutorial Java Corejava Dataconversion Int Conversion from int to boolean

 
 

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

Conversion from int to boolean:

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

Description:

This program will take an int value from console and provide a conversion to boolean type data(true/false).The line int myint = Integer.parseInt(buffreader.readLine()); is used to read the int value from console and store in myint variable. The line Boolean myboolean = (myint!=0); checks the condition if int value is not equal to 0 print a true otherwise false.

Code:

import java.io.*;

class inttoboolean {
	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());
			Boolean myboolean = (myint != 0);
			System.out.println("Convert value from int to boolean is: "
					+ myboolean);
		} catch (Exception e) {
			System.out.println(" Error " + e);
		}
	}
};
 

Output:

Download this code

Related Tags for Conversion from int to boolean:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.