JAVA随机颜色工具类
public class RandomColorUtil { public static String getColor() { //红色 String red; //绿色 String green; //蓝色 String blue; //生成随机对象 Random random = new Random(); //生成红色颜色代码 red = Integer.toHexString(random.nextInt(256)).toUpperCase(); //生成绿色颜色代码 green = Integer.toHexString(random.nextInt(256)).toUpperCase(); //生成蓝色颜色代码 blue = Integer.toHexString(random.nextInt(256)).toUpperCase(); //判断红色代码的位数 red = red.length() == 1 ? "0" + red : red; //判断绿色代码的位数 green = green.length() == 1 ? "0" + green : green; //判断蓝色代码的位数 blue = blue.length() == 1 ? "0" + blue : blue; return "#" + red + green + blue; } }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。