Probability of getting two consecutive heads after choosing a random coin among two different types of coins | Java program to get the probability of getting two consecutive heads ; Function to return the probability of getting two consecutive heads ; Formula derived from Bayes 's theorem ; Driver code ; given the probability of getting a head for both the coins
import java . io . * ; class GFG { static double getProbability ( double p , double q ) { p /= 100 ; q /= 100 ; double probability = ( p * p + q * q ) / ( p + q ) ; return probability ; } public static void main ( String [ ] args ) { double p , q ; p = 80 ; q = 40 ; System . out . println ( getProbability ( p , q ) ) ; } }