[Java] Color the standard output to the terminal

Please note that the variable *** i *** has changed to 0-7.


public class Color{
    public static void main(String[] args){
        //Change the font color
        for(int i=0;i<8;i++){
            //int i =0;
	    System.out.println("\u001b[00;3"+i+"m esc[00;3"+i+" \u001b[00m");
        //Change the background color
        for(int i=0;i<8;i++){
	    System.out.println("\u001b[00;4"+i+"m esc[00;4"+i+" \u001b[00m");	

Output result スクリーンショット 2019-04-07 20.44.29.png

You can color it like this

Also, if you use it frequently, I think it's a good idea to make stock first like this.


public class Color{
    public static void main(String[] args){
        String red    = "\u001b[00;31m";
        String green  = "\u001b[00;32m";
        String yellow = "\u001b[00;33m";
        String purple = "\u001b[00;34m";
        String pink   = "\u001b[00;35m";
        String cyan   = "\u001b[00;36m";   
        String end    = "\u001b[00m";
        String[] names = new String[]{red,green,yellow,purple,pink,cyan};
        for(int i=0; i< names.length; i++){        

Command line スクリーンショット 2019-04-07 21.20.01.png

Recommended Posts

[Java] Color the standard output to the terminal
Output of the book "Introduction to Java"
From terminal to Ruby (standard input / output)
Input to the Java console
(´-`) .. oO (I want to easily find the standard output "Hello".
[Java] I want to test standard input & standard output with JUnit
Log output to file in Java
Welcome to the Java Library Swamp! !!
The road from JavaScript to Java
[Java] How to use the File class
Java reference to understand in the figure
Introduction to java for the first time # 2
[Java] How to use the hasNext function
Java SE8 Silver ~ The Road to Pass ~
[Java] How to use the HashMap class
About the procedure for java to work
[Java] How to use the toString () method
[Java] Use cryptography in the standard library
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
[Java] How to output and write files!
How to output Java string to console screen
[Java] How to get the current directory
Ransack sort_link How to change the color!
[Processing × Java] How to use the class
How to install the legacy version [Java]
How to get the date in java
[Java] How to use the Calendar class
ActiveRecord prints the SQL query that is actually issued to standard output
[Java] output, variables
Try adding text to an image in Scala using the Java standard library
[Java] How to use Thread.sleep to pause the program
How to color code console output in Eclipse
Ruby standard output
Memo: [Java] Process the read csv (extract, change according to the conditions) and output
Java standard logger
Output of how to use the slice method
[Java] (for MacOS) How to set the classpath
[Java] Introduction to Java
How to use the replace () method (Java Silver)
I tried to output multiplication table in Java
[Java] Judgment by entering characters in the terminal
[Java / PostgreSQL] Connect the WEB application to the database
Introduction to java
[Java] How to get the redirected final URL
[Java] Memo on how to write the source
[Java] How to get the authority of the folder
[Java] Something is displayed as "-0.0" in the output
[Java] Try to solve the Fizz Buzz problem
How to check Rails commands in the terminal
Java Welcome to the Swamp of 2D Arrays
[Java] How to get the URL of the transition source
[Ruby] How to use standard output in conditional branching
[Java] How to omit the private constructor in Lombok
[Java] I want to calculate the difference from the date
How to write Scala from the perspective of Java
How to input / output IBM mainframe files in Java?
Try implementing the Eratosthenes sieve using the Java standard library
Convert the array of errors.full_messages to characters and output
[Java] How to extract the file name from the path
[Java] How to encrypt with AES encryption with standard library