Home Tutorial Java Corejava Dataconversion Short Conversion from short to boolean

 
 

Share on Google+Share on Google+
Conversion from short to boolean
Posted on: September 6, 2010 at 12:00 AM
Advertisement
In this tutorial we will learn how to convert a short type data to boolean type.

Conversion from short to boolean:

In this tutorial we will learn how to convert a short type data to boolean type.

Description:

This program will take a short type value from console and provides a conversion to boolean type. The line short myshort = Short.parseShort(buffreader.readLine()); reads the short type data from console. The line boolean mybool = (myshort!=0); checks the condition if myshort value is not equal to zero the boolean value will be true otherwise false.

Code:

import java.io.*;

class shorttoboolean {
public static void main(String[] args) {
try {
// Reads the value from console
BufferedReader buffreader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("---Data Conversion from short type to boolean type---");
System.out.println("Enter short type value: ");
// Read short type data
short myshort = Short.parseShort(buffreader.readLine());
// Convert short type data to boolean type
boolean mybool = (myshort != 0);
System.out.println("Converted value from short type to boolean type is : " + mybool);
} 
catch (Exception e) {
System.out.println(" Error " + e);
}
}
}
 

Output:

Download this code

Advertisement

Related Tags for Conversion from short to boolean:


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 6, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com