Power
Java Program to find X raised to the power Y, where X and Y are entered number by user.
package loops;
import java.util.Scanner;
public class Power
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter two numbers:");//2 4
int a=input.nextInt();//x=2
int b=input.nextInt();//y=4
int result=1;
for(int i=1;i<=b;i++)
{
result*=a;
}
System.out.println(a+" power "+b+" is "+result);
}
}
Comments
Post a Comment