Find the winner in nim | Java to find nim - game winner ; function to find winner of NIM - game ; case when Alice is winner ; when Bob is winner ; Driver code
class GFG { static String findWinner ( int A [ ] , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) res ^= A [ i ] ; if ( res == 0 n % 2 == 0 ) return " Alice " ; else return " Bob " ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 4 , 3 , 5 } ; int n = A . length ; System . out . print ( " Winner ▁ = ▁ " + findWinner ( A , n ) ) ; } }