Check if quantities of 3 distinct colors can be converted to a single color by given merge | Java program for the above approach ; Function to check whether it is possible to do the operation or not ; Calculate modulo 3 of all the colors ; Check for any equal pair ; Otherwise ; Driver Code ; Given colors ; Function Call
import java . util . * ; class GFG { static boolean isPossible ( int r , int b , int g ) { r = r % 3 ; b = b % 3 ; g = g % 3 ; if ( r == b b == g g == r ) { return true ; } else { return false ; } } public static void main ( String [ ] args ) { int R = 1 , B = 3 , G = 6 ; if ( isPossible ( R , B , G ) ) { System . out . print ( " Yes " + "NEW_LINE"); } else { System . out . print ( " No " + "NEW_LINE"); } } }