将 int 转换为 boolean 且指定转换值的 Java 程序
要将 int 转换为 boolean,我们首先取以下 int。
int one = 1; int two = 1; int three = 0;
我们嵌套了 if-else 语句来显示 true 或 false 值。此处,值“one”与“two”即 1 相同;因此,如下所示的内容起作用 −
else if (one.equals(two)) {
System.out.println(true);
}上述显示“true”,就这样,我们将 int 转换为了 boolean。
现在,让我们看一看完整示例,以了解如何将 int 转换为 Boolean。
示例
public class Demo {
public static void main(String[] args) {
int one = 1;
int two = 1;
int three = 0;
// int to Boolean
if (one == two) {
System.out.println(true);
} else if (one == three) {
System.out.println(false);
}
}
}输出
True
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP