將 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