Exponentiation in logarithmic time Input: Real number y and Integer number x
Output: x^y 
Constraint: Must be done in O(log(y)) time.


Notice that O(log(y)) is O(length-of(y)).

public static double expon(double x, int y){
    double result = 1.0;

    double part = x;
    for (int i = 0; i &lt; 32; i++){
        if (((y &gt;&gt; i) &amp; 1) == 1){
            result *= part;
        }
        part *= part;
    }   

    return result;
}
Your code is lacking comments that explain the why, ideally every non-trivial math programme should include a brief description of the algoritmh used.