Run Code
|
API
|
Code Wall
|
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 x, int n){// x^n int result = 1; while(n>0){ if(n%2 == 1){ result *= x; } n /= 2; x *= x; } return result; } public static void main(String args[]) { System.out.println("2^2=" + pow(2, 2)); System.out.println("2^3=" + pow(2, 3)); System.out.println("2^4=" + pow(2, 4)); System.out.println("2^5=" + pow(2, 5)); } }
run
|
edit
|
history
|
help
0
Huffman Encoding Tree v2
Wenfeng Ou
Most views runner!
1
1 to 100 except 30 to40
1.5
Java messing around
asdasd
piglatin
SalesmenEarnings