Convert RGB to Hex Color using Java

String.format method

package app;

public class Main
{
    public static void main(String[] args)
    {
        int r = 128;
        int g = 96;
        int b = 194;
        String hexColor = String.format("#%02x%02x%02x", r, g, b);

        System.out.println(hexColor);
    }
}

Leave a Comment

Cancel reply

Your email address will not be published.