Maximizing Probability of one type from N containers | Java program to find maximum probability of getting a copy ' A ' from N ; Returns the Maximum probability for Drawing 1 copy of number A from N containers with N copies each of numbers A and B ; Pmax = N / ( N + 1 ) ; Driver code ; 1. N = 1 ; 2. N = 2 ; 3. N = 10
class GFG { static double calculateProbability ( int N ) { double probability = ( double ) N / ( N + 1 ) ; return probability ; } public static void main ( String [ ] args ) { int N ; double probabilityMax ; N = 1 ; probabilityMax = calculateProbability ( N ) ; System . out . println ( " Maximum ▁ Probability ▁ for " + " ▁ N ▁ = ▁ " + N + " ▁ is , ▁ " + Math . round ( probabilityMax * 10000.0 ) / 10000.0 ) ; N = 2 ; probabilityMax = calculateProbability ( N ) ; System . out . println ( " Maximum ▁ Probability ▁ for ▁ N ▁ = ▁ " + N + " ▁ is , ▁ " + Math . round ( probabilityMax * 10000.0 ) / 10000.0 ) ; N = 10 ; probabilityMax = calculateProbability ( N ) ; System . out . println ( " Maximum ▁ Probability ▁ for ▁ N ▁ = ▁ " + N + " ▁ is , ▁ " + Math . round ( probabilityMax * 10000.0 ) / 10000.0 ) ; } }