English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Javaプログラム、intを指定の変換値のブール値に変換します

intをbooleanに変換するには、まず以下のintを取得します。

int one = 1;
int two = 1;
int three = 0;

ifをネストして-else文を使用してtrueまたはfalseの値を表示します。ここでは、値「 1「と」 2「同じ」、つまり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からBooleanへの変換-
      if (one == two) {
         System.out.println(true);
      } else if (one == three) {
         System.out.println(false);
      }
   }
}

出力結果

True