RandomColor

/**
 * 
 */
package utils;


/**
 * @Title:RandomColor.java
 * @Package: utils
 * @Description:生成随机颜色
 * @author:LJJ
 * @date:2014-1-15 下午11:29:51
 * @version V1.0
 */


import java.util.Random;


/**
 * 
 * @author:LJJ
 * @date:2014-1-15 下午11:29:51
 * @version V1.0
 */
public class RandomColor {
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;
// 生成十六进制颜色值
String color = "#" + red + green + blue;


System.out.println(color);
return color;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值