Home > Java > javaTutorial > body text

Writing console output

Mary-Kate Olsen
Release: 2024-11-06 02:26:02
Original
899 people have browsed it

Gravando a saída do console

Console Output in Java:

  • Initially, Java only offered byte streams for console output; Starting with Java 1.1, character streams were added for greater portability.
  • System.out is still widely used for simple console output, and all previous examples in the book have used it.

Print() and println() methods:

  • These are methods of the PrintStream class (System.out object type) and facilitate data output to the console.
  • System.out allows simple outputs despite being a stream of bytes.

PrintStream write(int valbyte) method:

  • Allows you to write a specific byte to the console.
  • Only the 8 least significant bits of valbyte are written.

Example of use:

class WriteDemo {
    public static void main(String args[]) {
        int b = 'X';
        System.out.write(b);
        System.out.write('\n');
    }
}

Copy after login
  • Use: write() is less frequent, as print() and println() are more practical for general output.

PrintStream printf() and format() methods:

  • Advanced Formatting Control: Allows you to control the output format, including decimal places, minimum field width and display of negative values.
  • These methods, although useful, were not used in the examples in this book, but are recommended for those who want to explore detailed data formatting in Java.

This snippet explains how data output to the console is managed in Java and shows additional methods for controlling formatting, providing simple and advanced options for displaying data.

The above is the detailed content of Writing console output. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!