Método PrintStream println (booleano) en Java con ejemplos

El método println(boolean) de PrintStream Class en Java se usa para imprimir el valor booleano especificado en la secuencia y luego dividir la línea. Este valor booleano se toma como parámetro.

Sintaxis:

public void println(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 println (booleano):

Programa 1:

// Java program to demonstrate
// PrintStream println(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 println() method
            // This will put the booleanValue in the
            // stream till it is printed on the console
            stream.println(true);
  
            stream.flush();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}
Producción:

true

Programa 2:

// Java program to demonstrate
// PrintStream println(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 println() method
            // This will put the booleanValue in the
            // stream till it is printed on the console
            stream.println(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 *