Calculate Power of a Number in Java.
Calculate Power of a number using java with for loop.
EXAMPLE :-
public class power {
public static void main(String[] args) {
int number = 3, p = 2;
long result = 1;
int i=p;
while (i != 0)
{
result *= number;
--i;
}
System.out.println(number+"^"+p+" = "+result);
}
}
OUTPUT
3^2 = 9
No comments:
Post a Comment
Please do not any spam link in Comment Box