Método PrintWriter print(char) en Java con ejemplos

El método print(char) de PrintWriter Class en Java se usa para imprimir el valor char especificado en la secuencia. Este valor de char se toma como parámetro.

Sintaxis:

public void print(char charValue)

Parámetros: este método acepta un parámetro obligatorio charValue que es el valor de carácter que se escribirá en la secuencia.

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

Los siguientes métodos ilustran el funcionamiento del método print(char):

Programa 1:

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

A

Programa 2:

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

G

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 *