Count number of triplets with product equal to given number | Java program to count triplets with given product m ; Method to count such triplets ; Consider all triplets and count if their product is equal to m ; Driver method
class GFG { static int countTriplets ( int arr [ ] , int n , int m ) { int count = 0 ; for ( int i = 0 ; i < n - 2 ; i ++ ) for ( int j = i + 1 ; j < n - 1 ; j ++ ) for ( int k = j + 1 ; k < n ; k ++ ) if ( arr [ i ] * arr [ j ] * arr [ k ] == m ) count ++ ; return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 6 , 2 , 3 , 8 } ; int m = 24 ; System . out . println ( countTriplets ( arr , arr . length , m ) ) ; } }