java随机生成十六进制颜色

public static void main(String[] args) {
		
		  String r,g,b;  
		  Random random = new Random();  
		  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 ;  
		    
		  System.out.println( r+g+b);;  
		
	}

3A9890


http://wandejun1012.iteye.com/blog/1179801

你可能感兴趣的:(java随机生成十六进制颜色)