Given a integer value, the task is to convert this integer value into a boolean value in Java.
Examples:
Input: int = 1 Output: true Input: int = 0 Output: false
Approach:
Example 1:
// Java Program to convert integer to boolean public class GFG { public static void main(String[] args) { // The integer value int intValue = 1; // The expected boolean value boolean boolValue; // Check if it's greater than equal to 1 if (intValue >= 1) { boolValue = true; } else { boolValue = false; } // Print the expected integer value System.out.println( intValue + " after converting into boolean = " + boolValue); } }
Output:
1 after converting into boolean = true
Example 2:
// Java Program to convert integer to boolean public class GFG { public static void main(String[] args) { // The integer value int intValue = 0; // The expected boolean value boolean boolValue; // Check if it's greater than equal to 1 if (intValue >= 1) { boolValue = true; } else { boolValue = false; } // Print the expected integer value System.out.println( intValue + " after converting into boolean = " + boolValue); } }
Output:
0 after converting into boolean = false
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.