Modus Operandi interview question

Implement a recursive Java function that calculates a number "n" to the "mth" power.

Interview Answer

Anonymous

15 Apr 2013

public static float pow( int n , int m ) { if( m == 0 ) return (float)1; if( n == 0 && m == 0 ) return Math.pow( 0 , 0 ); /* ERROR HERE */ if( m < 0 ) return pow( n , m * -1 ); return n * pow( n , m - 1 ); }