21 Matchsticks Problem | Java implementation of the approach ; Function to return the optimal strategy ; Removing matchsticks in blocks of five ; Driver code
class GFG { static void TwentyoneMatchstick ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i += 1 ) { System . out . print ( 5 - arr [ i ] + " ▁ " ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 4 , 2 , 2 } ; int N = arr . length ; TwentyoneMatchstick ( arr , N ) ; } }