public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print(String.format("\033[%dm%s\033[0m", 32, "[Tools:\\]$ ")); while(scanner.hasNext()){ String cmd = scanner.next(); if(cmd.equals("exit")){ System.out.println("退出应用"); return; }else{ System.out.println("输入的指令: " + cmd); System.out.print(String.format("\033[%dm%s\033[0m", 32, "[Tools:\\]$ ")); } } } } 备注: String.format("\033[%dm%s\033[0m", colour, content); colour常用值:
[ 红色 ]31
[ 黄色 ]32
[ 橙色 ]33
[ 蓝色 ]34
[ 紫色 ]35
[ 绿色 ]36