Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
5
Help us understand the problem. What is going on with this article?
@DisneyAladdin

【Java】標準出力に色をつける

変数iが0-7へ変化してるのでそこに注意してください

Color.java
public class Color{
    public static void main(String[] args){
        //文字色を変える
        for(int i=0;i<8;i++){
            //int i =0;
        System.out.println("\u001b[00;3"+i+"m esc[00;3"+i+" \u001b[00m");
        }
        //背景色を変える
        for(int i=0;i<8;i++){
        System.out.println("\u001b[00;4"+i+"m esc[00;4"+i+" \u001b[00m");   
        }
    }
}

出力結果
スクリーンショット 2019-04-07 20.44.29.png

こんなかんじで色付けできます

また,頻繁に使うって人はこんなかんじで先にストック作っておくのもいいと思います

Color.java
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++){        
        System.out.println(names[i]+"hello"+end);
        }
    }
}

コマンドライン
スクリーンショット 2019-04-07 21.20.01.png

5
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
DisneyAladdin
Pythonが大好物です.

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
5
Help us understand the problem. What is going on with this article?