Count of total Heads and Tails after N flips in a coin | Java program to count total heads and tails after N flips in a coin ; Function to find count of head and tail ; Check if initially all the coins are facing towards head ; Check if initially all the coins are facing towards tail ; Driver code
import javafx . util . Pair ; public class Main { public static Pair < Integer , Integer > count_ht ( char s , int N ) { Pair < Integer , Integer > p = new Pair < Integer , Integer > ( 0 , 0 ) ; if ( s == ' H ' ) { p = new Pair < Integer , Integer > ( ( int ) Math . floor ( N / 2.0 ) , ( int ) Math . ceil ( N / 2.0 ) ) ; } else if ( s == ' T ' ) { p = new Pair < Integer , Integer > ( ( int ) Math . ceil ( N / 2.0 ) , ( int ) Math . floor ( N / 2.0 ) ) ; } return p ; } public static void main ( String [ ] args ) { char C = ' H ' ; int N = 5 ; Pair < Integer , Integer > p = count_ht ( C , N ) ; System . out . println ( " Head ▁ = ▁ " + p . getKey ( ) ) ; System . out . println ( " Tail ▁ = ▁ " + p . getValue ( ) ) ; } }