Find the winner of a game of donating i candies in every i | Java Program for above approach ; Function to find the winning player in a game of donating i candies to opponent in i - th move ; Steps in which number of candies of player A finishes ; Steps in which number of candies of player B finishes ; If A 's candies finishes first ; Otherwise ; Driver code ; Candies possessed by player A ; Candies possessed by player B
class GFG { static void stepscount ( int a , int b ) { int chanceA = 2 * a - 1 ; int chanceB = 2 * b ; if ( chanceA < chanceB ) { System . out . print ( " B " ) ; } else if ( chanceB < chanceA ) { System . out . print ( " A " ) ; } } public static void main ( String [ ] args ) { int A = 2 ; int B = 3 ; stepscount ( A , B ) ; } }