I want a program that takes an int x
as parameter and returns 2^x
. The implementation is not allowed to use power of.
public int double2 (int x) {
int r = 2;
int y = 1;
for (int i=0; i < x; i++){
y = r* y;
}
return y;
}
Do you think this is a right solution?