Check out the java.lang.Math class. It has a method for raising powers (pow) plus lots of other useful stuff.
I suspect your homework is a programming exercise rather than a Math problem, but I think there is a simple way to calculate this. It's a long time since I was at high school, but to determine "n", can't you just calc the log to base 2 of the target and take the integer part? e.g. log to base 2 of 100 is 6.629 so n = 6.
In Java, a method to do this would be:
This runs into trouble for very large numbers due to the size of a double. e.g. 1 followed by 1000 digits is too large. If the target is always a power of 10, then you could use: