- 格式
System.out.format("\33[字体颜色数字;背景颜色数字;字体格式要输出的内容%n");
※ 注:字体格式和要输出的内容是挨着的中间没有任何符号
%n:换行符
字体格式:1m(加粗)、2m(正常)、3m(斜体)、4m(下划线)
- 示例:
- 代码:
System.out.format("\033[32;1m%s\033[0m", "Python返回数据:");
- 字体颜色
字体颜色数字 | 颜色 |
---|---|
30 | 黑色 |
31 | 红色 |
32 | 绿色 |
33 | 不知道什么黄的黄色 |
34 | 蓝色 |
35 | 紫色 |
36 | 蒂芙尼蓝 |
37 | 深灰色 |
38 | 浅灰色 |
public class FontColor {
public static void main(String[] args) {
System.out.println("普通输出的白色");
System.out.format("\33[30;1m30:黑色%n");
System.out.format("\33[31;1m31:红色%n");
System.out.format("\33[32;1m32:绿色%n");
System.out.format("\33[33;1m33:不知道什么黄的黄色%n");
System.out.format("\33[34;1m34:蓝色%n");
System.out.format("\33[35;1m35:紫色%n");
System.out.format("\33[36;1m36:蒂芙尼蓝%n");
System.out.format("\33[37;1m37:深灰色%n");
System.out.format("\33[38;1m38:浅灰色%n");
}
3. 背景颜色
背景颜色数字 | 颜色 |
---|---|
40 | 黑色 |
41 | 红色 |
42 | 绿色 |
43 | 不知道什么黄的黄色 |
44 | 蓝色 |
45 | 紫色 |
46 | 蒂芙尼蓝 |
47 | 深灰色 |
48 | 浅灰色 |
public class BackgroundColor {
public static void main(String[] args) {
System.out.format("\33[40;1m40:背景黑色%n");
System.out.format("\33[41;1m41:背景红色%n");
System.out.format("\33[42;1m42:背景绿色%n");
System.out.format("\33[43;1m43:背景不知道什么黄的黄色%n");
System.out.format("\33[44;1m44:背景蓝色%n");
System.out.format("\33[45;1m45:背景紫色%n");
System.out.format("\33[46;1m46:背景蒂芙尼蓝色%n");
System.out.format("\33[47;1m47:背景深灰色%n");
System.out.format("\33[48;1m48:背景浅灰色%n");
}
}