Product of non | Java program to find the product of all non - repeated elements in an array ; Function to find the product of all non - repeated elements in an array ; sort all elements of array ; Driver code
import java . util . Arrays ; class GFG { static int findProduct ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int prod = 1 * arr [ 0 ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] != arr [ i + 1 ] ) { prod = prod * arr [ i + 1 ] ; } } return prod ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 1 , 1 , 4 , 5 , 6 } ; int n = arr . length ; System . out . println ( findProduct ( arr , n ) ) ; } }