Conversion from short to boolean


 

Conversion from short to boolean

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

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

Ads