Sunday, September 21, 2014

Find power of given value without using any of Math method

private static void findPowerOfValue(int findValue, int powerValue) {
        int temp = 0;
        while (findValue > powerValue) {
            temp = findValue / powerValue;
            if ((temp % powerValue) != 0) {
                System.out.println("Given value : "+findValue+" is not power of "+powerValue);
                break;
            } else {
                System.out.println("Given value : "+findValue+" is power of "+powerValue);
            }
            findValue = findValue / powerValue;
        }
    }

No comments:

Post a Comment