fork(1) download
  1. class Example {
  2. public static void main(String[] args) {
  3. System.out.println(getHex(255, 255, 255)); // #fff
  4. System.out.println(getHex(255, 240, 255)); // #fff0ff
  5. }
  6.  
  7. static String getHex(int r, int g, int b) {
  8. return String.format("#%02x%02x%02x", r, g, b).replaceAll("^#([a-fA-F])\\1([a-fA-F])\\2([a-fA-F])\\3$", "#$1$2$3");
  9. }
  10. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
#fff
#fff0ff