Método de impresión PrintStream (booleano) en Java con ejemplos

El método de impresión (booleano) de PrintStream Class en Java se usa para imprimir el valor booleano especificado en la secuencia. Este valor booleano se toma como parámetro.

Sintaxis:

public void print(boolean booleanValue)

Parámetros: este método acepta un parámetro obligatorio booleanValue que es el valor booleano que se escribirá en el flujo.

Valor devuelto: este método no devuelve ningún valor.

Los siguientes métodos ilustran el funcionamiento del método de impresión (booleano):

Programa 1:

// Java program to demonstrate
// PrintStream print(boolean) method
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
  
            // Create a PrintStream instance
            PrintStream stream
                = new PrintStream(System.out);
  
            // Print the boolean value 'true'
            // to this stream using print() method
            // This will put the booleanValue in the
            // stream till it is printed on the console
            stream.print(true);
  
            stream.flush();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
Producción:

true

Programa 2:

// Java program to demonstrate
// PrintStream print(boolean) method
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
  
        try {
  
            // Create a PrintStream instance
            PrintStream stream
                = new PrintStream(System.out);
  
            // Print the boolean value 'false'
            // to this stream using print() method
            // This will put the booleanValue in the
            // stream till it is printed on the console
            stream.print(false);
  
            stream.flush();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
Producción:

false

Publicación traducida automáticamente

Artículo escrito por Kirti_Mangal y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *