mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 03:59:38 +08:00
Formatted with Google Java Formatter
This commit is contained in:
@ -21,26 +21,28 @@ public class BinaryPow {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function for testing binary exponentiation
|
* Function for testing binary exponentiation
|
||||||
* @param a the base
|
*
|
||||||
|
* @param a the base
|
||||||
* @param p the exponent
|
* @param p the exponent
|
||||||
*/
|
*/
|
||||||
public static void test(int a, int p) {
|
public static void test(int a, int p) {
|
||||||
int res = binPow(a, p);
|
int res = binPow(a, p);
|
||||||
assert res == (int) Math.pow(a, p) : "Incorrect Implementation";
|
assert res == (int) Math.pow(a, p) : "Incorrect Implementation";
|
||||||
System.out.println(a + "^" + p + ": " + res);
|
System.out.println(a + "^" + p + ": " + res);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Main Function to call tests
|
/**
|
||||||
*
|
* Main Function to call tests
|
||||||
|
*
|
||||||
* @param args System Line Arguments
|
* @param args System Line Arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// prints 2^15: 32768
|
// prints 2^15: 32768
|
||||||
test(2, 15);
|
test(2, 15);
|
||||||
|
|
||||||
// prints 3^9: 19683
|
// prints 3^9: 19683
|
||||||
test(3,9);
|
test(3, 9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user