Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,025 questions

51,979 answers

573 users

How to find the average between RGB colors c1 and c2 in Java

1 Answer

0 votes
import java.awt.Color;

public class Program {
    public static void main(String[] args) {
        Color c1 = new Color(255, 100, 50);
        Color c2 = new Color(50, 170, 200);

        int avgR = (c1.getRed() + c2.getRed()) / 2;
        int avgG = (c1.getGreen() + c2.getGreen()) / 2;
        int avgB = (c1.getBlue() + c2.getBlue()) / 2;

        String average = String.format("#%02X%02X%02X", avgR, avgG, avgB);
        System.out.println("Average Color: " + average);
    }
}

 
 
/*
run:
 
Average Color: #98877D
 
*/

 



answered Jun 18, 2025 by avibootz
...