Maximum number of objects that can be created as per given conditions | Java program for the above problem ; Function for finding the maximum number of objects from N type - 1 and M type - 2 items ; Storing minimum of N and M ; Storing maximum number of objects from given items ; Driver Code
class GFG { static int numberOfObjects ( int N , int M ) { int initial = Math . min ( N , M ) ; int last = ( N + M ) / 3 ; return Math . min ( initial , last ) ; } public static void main ( String [ ] args ) { int N = 8 ; int M = 7 ; System . out . println ( numberOfObjects ( N , M ) ) ; } }