int clip(int n) { return Math.max(0, Math.min(n, 255)); } String rgb(int r, int g, int b) { r = clip(r); g = clip(g); b = clip(b); return String.format("%02x%02x%02x", new Object[] { r, g, b}).toUpperCase(); } show(); rgb(255, 255, 255); // returns FFFFFF rgb(255, 255, 300); // returns FFFFFF rgb(0,0,0); // returns 000000 rgb(148, 0, 211); // returns 9400D3 rgb(-20,275,125); // returns 00FF7D
Run this code using AJShA Android app
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
BeanShell
Run this code using AJShA Android app