Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
pow x^n
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static int pow(int xx, int nn){// x^n int result = 1, x=xx, n=nn; for(;n>0;n/=2, x*=x){ if(n%2 == 1){ result *= x; } } return result; } public static void main(String args[]) { int maxN = 10; for(int i=0; i<=maxN; i++){ System.out.println("2^"+i+"=" + pow(2, i)); } } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Just numbers
calc
hello!
MyBirdClass
frequency of char
Le saviez-vous ?
output1
Black Jack by Craig
Sum of ODD and EVEN numbers in an array
Catalan number optimised
Please log in to post a comment.