求解释一下下列语句是什么意思?表示看不懂!//获取十六进制的颜色代码.例如"#6E36B4",ForHTML.//java.lang.Integer.toHexString()方法用法实例教程//此方法返回的字符串表示的无符号...
求解释一下下列语句是什么意思?表示看不懂!
//获取十六进制的颜色代码.例如 "#6E36B4" , For HTML.
//java.lang.Integer.toHexString()方法用法实例教程
//此方法返回的字符串表示的无符号整数参数所表示的值以十六进制(基数为16),如0123456789ABCDEF。
import java.util.Random;
public class ColorUtil {
public static String getRandColorCode() {
String r, g, b;
Random random = new Random();
//随机产生一个0-255的整型数,然后将这个数转化成十六进制,且字母为大写字母
r = Integer.toHexString(random.nextInt(256)).toUpperCase();
g = Integer.toHexString(random.nextInt(256)).toUpperCase();
b = Integer.toHexString(random.nextInt(256)).toUpperCase();
r = r.length() == 1 ? "0" + r : r;
g = g.length() == 1 ? "0" + g : g;
b = b.length() == 1 ? "0" + b : b;
return r + g + b;
}
public static void main(String[] args) {
System.out.println(getRandColorCode());
}
}
展开