📜  在方法 java 代码示例中查找数字的幂

📅  最后修改于: 2022-03-11 14:52:46.313000             🧑  作者: Mango

代码示例2
package javaprogramms;
import java.util.Scanner;


public class powermethod {
public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    
    System.out.println("Enter Base Number: ");
    int base=sc.nextInt();
    System.out.println("Enter Power Number: ");
    int pw=sc.nextInt();
    
    power(base,pw);
}
public static void power(int base, int pw) {
    int res=1;
    while(pw>0) {
        res=res*base;
        pw--;
    }
    System.out.println("Result: "+res);
}
}