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

El programa Java convierte int a un valor booleano específico

Para convertir int a boolean, primero obtenemos el siguiente int.

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

Hemos anidado if-else para mostrar valores true o false. Aquí, el valor “ 1”y “ 2”es el mismo, es decir1; por lo tanto, el siguiente trabajo-

else if (one.equals(two)) {
   System.out.println(true);
}

La salida superior es “true”, por lo tanto, convertimos int a boolean.

Ahora veamos el ejemplo completo para entender cómo convertir int a Booleano.

Ejemplo

public class Demo {
   public static void main(String[] args) {
      int one = 1;
      int two = 1;
      int three = 0;
      //Entero a Booleano-
      if (one == two) {
         System.out.println(true);
      } else if (one == three) {
         System.out.println(false);
      }
   }
}

Resultado de salida

Verdadero